Ever needed to send an HTML email via PHP only to find that it won’t freakin render as HTML in Gmail? Well I did. Of course the email renders correctly in every other mail provider (Yahoo, Hotmail, Outlook etc..).
Turns out that the problem is in the headers. If you’re doing something like this:
$headers = "From: john@example.com\r\n"; $headers .= "Reply-To: john@example.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
or this:
$headers = "From: john@example.com" . "\r\n"; $headers .= "Reply-To: john@example.com" . "\r\n"; $headers .= "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
…then try something like this instead:
$headers = "From: john@example.com\n"; $headers .= "Reply-To: john@example.com\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1";
The difference is in the line-breaks. Using ‘\r\n’ causes two line-breaks in Gmail whereas using just ‘\n’ keeps Gmail happy. And keeping Gmail happy is extremely important if you’re sending out an email!
Just got this problem , thx for ur info.
Legend, thank you!
Thanks man, you rule buddy.
This mail issue has been bugging me for quite a while works perfectly now.
Thank you so much!
Kind Regards
Nick
Thank you for the evry useful information.
Did anyone tested this fix on other email providers?
Do they parse it correctly?
Yep, this works across all major email clients – gmail, yahoo, hotmail, outlook etc.
Thank you sooooo much your help. u saved my one full day… 🙂
You’re beautiful, solved my headache with gmail’s silly neurosis.
Dear sir,
please help me in my php coding,
1. $headers = ‘MIME-Version: 1.0\n”;
2. $headers .= ‘Content-type: text/html; charset=iso-8859-1\n”;
3. $headers .= ‘From: ‘.$_POST[‘businessName’].’ ‘ . “\r\n” .
4. ‘Reply-To: ‘.$_POST[‘businessName’].’ ‘ . “\r\n” .
5. ‘X-Mailer: PHP/’ . phpversion();
6.
7. /*Kirim Email*/
8. mail($to, $subject, $jcitems, $headers);
9.
10. /*redirecting user to Thank you page*/
11. Header(‘Location: ‘.$_POST[‘urlSuccess’].”);
12. ?>
in line 3 and 11, i get message:
Parse error: syntax error, unexpected T_STRING
Thank you for your ‘\n’ and your help.
Best Regard.
Merely wanna remark that you have a very decent site, I love the style and design it really stands out.
Thanks buddy. You saved me alot
As of February 19, 2014, this did not work for me. I have been trying to figure out why I cannot get gmail to render the html e-mail properly. I tried this, but gmail is still screwing up.