Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

mime - PHP mail formatting issue - Why do CRLF header line endings break HTML email in Outlook?

I'm using the PHP native mail() function to send HTML emails and have a formatting problem in the users most common email client - Outlook 2007 (in addition to some other email clients) - all the html tags are exposed so it looks like gibberish to a non-web-developer.

I'm sending HTML email the same way that the PHP manual demos it. Example:

$message  = get_HTML_email_with_valid_formatting();
$headers  = "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=UTF-8
";
$headers .= "From: example.com <[email protected]>
";
$headers .= "Reply-To: [email protected]
";
mail('[email protected]', 'test', $message, $headers);

Because testing various email clients is hard, I have signed up with http://litmusapp.com/ so I can see a screenshot of the emails in 47 different email clients. Most are ok (e.g. gmail, thunderbird, Lotus Notes) but all the different versions of Outlook are not ok.

To fix the formatting issue I had do the following:

  1. Remove the $headers = "MIME-Version: 1.0 "; mail header.
  2. Ensure I end my headers with only " " instead of " ".

Does anyone know why I am getting better results with HTML emails when I do not conform to the manual?

Info:

  • I'm using postfix version 2.3.3 on RHEL 5.5.
  • PHP version 5.3.2
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If You use postfix<2.9, You can just put sendmail_path = "tr -d ' '|sendmail -t -i" into php.ini.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...