• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

php sending HTML emails

boycee

Gawd
Joined
Oct 2, 2001
Messages
735
Ok, I'm trying to send an HTML email.. So far I have this...

Code:
	//add From: header 
	$headers = "From: Email App <noreply@domain.com>\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("This the <b>HTML</b> version!")); 

	mail("myEmail@googlemail.com", "An HTML Message", "", $headers);

For some reason the HTML works in most email readers (horde/outlook/thunderbird) however, googlemail is letting me down. (I can't have that obv).

I know googlemail accepts html emails, and comparing the headers I still can't find the difference??

Any ideas?
 
I second the recommendation of PHPMailer. It makes sending HTML emails quite easy.
 
Cheers for the replies.

I did look at php mailer, but seams a bit overkill! I'll still check it out though.

Thing is with the above is it works in all email clients except googlemail. So I'm thinking there's maybe a header googlemail looks for which I'm not including?
 
overkill, perhaps. but if it solves the problem with minimal extra effort (to learn how to use phpmailer, but there are examples) then so be it. you might be talking milliseconds worth of overhead, which won't be noticed.
 
Yeah hmm.....

Ok so I just shoved the emailed lib in and used that! Using the SMTP option it does make things a lot easier and since it's only going to be called once every few weeks I think they can deal with the extra 0.001sec overhead lol!
 
also, while some (and myself at times) may find it enlightening to see the gritty details of how something works, like html emails with all the crazy headers and whatnot, more often than not you just want the damned thing to work :p
 
Computer time is cheap. Computer programmer time is expensive. Always remember that.
 
Back
Top