Page 1 of 1
mail() not sending html messages
Posted: Tue Sep 18, 2007 8:23 pm
by jdhorton77
I have a problem with one of my pages not wanting to send out messages as HTML format. It does send messages as text, so I think it must be in my headers. Can someone look over them and let me know if I'm just missing something. Thanks in advance.
Code: Select all
$headers = 'Content-type: text/html;charset=iso-8859-1'."\r\n".
'MIME-Version: 1.0'."\r\n".
'From: someone <webadmin@somewhere.com>'."\r\n".
'To: '.$row['friendname'].' <'.$eaddress.'>'."\r\n";
// message code here
if(!mail($eaddress,$subject,$message,$headers)) echo "Error in mailing system.";
Posted: Tue Sep 18, 2007 8:33 pm
by volka
You might be interested in
http://swiftmailer.org/
Posted: Tue Sep 18, 2007 8:47 pm
by jdhorton77
Not sure if the hosting company uses Swift or not. I would rather just use the mail function since I'm not going to be sending mass emails.
Posted: Tue Sep 18, 2007 10:08 pm
by feyd
The hosting company doesn't need to use Swiftmailer... you can choose that yourself.
Posted: Wed Sep 19, 2007 4:44 am
by aceconcepts
I use the following to send HTML emails and it works perfectly
Code: Select all
$to = "someone@destination.tld";
$subject = "Something...";
$message="<html>";
$from = $emailVar;
//add From: header
$headers = "From: " . $emailVar. "\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = uniqid("HTMLDEMO");
//tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/alternative" .
"; boundary = $boundary\r\n\r\n";
//message to people with clients who don't
//understand MIME
$headers .= "This is a MIME encoded message.\r\n\r\n";
//plain text version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/plain; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("This is the plain text version!"));
//HTML version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode($message));
mail($to,$subject,$message,$headers,"-f $from");