Formatting mail() headers "prettier"
am 21.09.2007 15:42:50 von phpCodeHead
Hello all,
Given the following code:
$FormSubmittedUserData = "John Doe ";
$to = 'myemail@emaildomain.nuts';
$subject = 'This is my subject';
$message = 'This is my email message.';
$headers = "From: $Email\r\nReply-To: $Email\r\n";
mail($to, $subject, $message, $headers);
I only get the email address in the recipient inbox From: or Sender:
columns.
I am trying to provide the mail() function with the properly formatted
headers to get an outcome of "FirstName LastName" appearing in
recipient's Sender: or From: column in their inbox.
Any help from anyone who has tackled this one before would be greatly
appreciated.
Thanks all,
Gene Kelley
www.bizflowdesigns.com
Re: Formatting mail() headers "prettier"
am 21.09.2007 16:08:49 von Steve
"phpCodeHead" wrote in message
news:1190382170.137879.235600@r29g2000hsg.googlegroups.com.. .
> Hello all,
>
> Given the following code:
>
> $FormSubmittedUserData = "John Doe ";
>
> $to = 'myemail@emaildomain.nuts';
> $subject = 'This is my subject';
> $message = 'This is my email message.';
> $headers = "From: $Email\r\nReply-To: $Email\r\n";
>
> mail($to, $subject, $message, $headers);
>
> I only get the email address in the recipient inbox From: or Sender:
> columns.
>
> I am trying to provide the mail() function with the properly formatted
> headers to get an outcome of "FirstName LastName" appearing in
> recipient's Sender: or From: column in their inbox.
>
> Any help from anyone who has tackled this one before would be greatly
> appreciated.
yeah, about that. a lot of people tackle the generation of email via php
outside of php's built in functionality (which sucks!)
i either use sendmail in a *nix env., or iis smtp to get the mail on its
way. if sendmail, use the exec and execOptions to command-line the mail
correctly, otherwise, just placing the email in the pickup directory in iis
will be sufficient.
hth.
================
class email
{
static function send(
$to ,
$from ,
$cc = '' ,
$bcc = '' ,
$subject ,
$text = '' ,
$html = '' ,
$companyName = '' ,
$logo = null ,
$dropDirectory = '' ,
$exec = '' ,
$execOptions = ''
)
{
$messageHtml = $html;
$html = '
';
if (isset($logo))
{
$image = file_get_contents($logo);
$image = chunk_split(base64_encode($image));
$html .= '
src="cid:logo" style="float:right;">
';
}
if ($messageHtml == ''){ $messageHtml = '' . $text; }
$html .= $messageHtml . '';
if ($text == ''){ $text = $html; }
$boundry = '----=' . md5(uniqid(rand()));
$related = '----=' . md5(uniqid(rand()));
$mail = "MIME-Version: 1.0\r\n";
$mail .= "TO: " . $to . "\r\n";
$mail .= "FROM: " . $from . "\r\n";
$mail .= "CC: " . $cc . "\r\n";
$mail .= "BCC: " . $bcc . "\r\n";
$mail .= "Subject: " . $subject . "\r\n";
$mail .= "Content-Type: multipart/related;
boundary=\"$related\"\r\n\r\n\r\n";
$mail .= "--$related\r\n";
$mail .= "Content-Type: multipart/alternative;
boundary=\"$boundry\"\r\n\r\n\r\n";
$mail .= "--$boundry\r\n";
$mail .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$mail .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$mail .= $text . "\r\n\r\n";
$mail .= "--$boundry\r\n";
$mail .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$mail .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$mail .= $html . "\r\n\r\n";
$mail .= "--$boundry--\r\n\r\n";
$mail .= "--$related\r\n";
$mail .= "Content-Type: image/jpeg\r\n";
$mail .= "Content-ID: logo\r\n";
$mail .= "Content-Disposition: attachment;
filename=\"logo.jpg\"\r\n";
$mail .= "Content-Transfer-Encoding: base64\r\n\r\n";
$mail .= $image . "\r\n\r\n";
$mail .= "--$related--\r\n\r\n";
$mail .= "-- End --\r\n";
$fileName = $dropDirectory . strtoupper(md5(uniqid(rand()))) . '.eml';
file_put_contents($fileName, $mail);
if (!$exec){ return $mail; }
exec($exec . $fileName . $execOptions);
@unlink($fileName);
return $mail;
}
}
?>