mail() not sending html messages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

mail() not sending html messages

Post 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.";
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You might be interested in http://swiftmailer.org/
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The hosting company doesn't need to use Swiftmailer... you can choose that yourself.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post 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");
Post Reply