PHP邮件格式问题-为什么CRLF标头行结尾会破坏Outlook中的HTML电子邮件? [英] PHP mail formatting issue - Why do CRLF header line endings break HTML email in Outlook?

查看:145
本文介绍了PHP邮件格式问题-为什么CRLF标头行结尾会破坏Outlook中的HTML电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP本机的mail()函数发送HTML电子邮件,并且在用户最常用的电子邮件客户端- Outlook 2007 (以及一些其他电子邮件)中存在格式问题客户)-所有html标记都已公开,因此对于非Web开发人员来说似乎有些胡言乱语.

我发送HTML电子邮件的方式与 PHP手册相同演示它.示例:

$message  = get_HTML_email_with_valid_formatting();
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "From: example.com <info@example.com>\r\n";
$headers .= "Reply-To: donotreply@example.com\r\n";
mail('me@example.com', 'test', $message, $headers);

因为很难测试各种电子邮件客户端,所以我已经注册了 http://litmusapp.com/我可以在47个不同的电子邮件客户端中看到电子邮件的屏幕截图.大多数都可以(例如gmail,雷鸟,Lotus Notes),但是所有不同版本的Outlook都不可以.

要解决格式问题,请执行以下操作:

  1. 删除$headers = "MIME-Version: 1.0\r\n";邮件标题.
  2. 确保我的标头仅以"\n"而不是"\r\n"结束.

有人不知道为什么我不遵守该手册时,使用HTML电子邮件可以获得更好的结果吗?

信息:

  • 我正在RHEL 5.5上使用 postfix 版本2.
  • .
  • PHP版本5.3.2

解决方案

您有2种解决方案:

  1. 将具有"sendmail_fix_line_endings"的Postfix升级到+2.9(最终!!!)请参阅: Postfix文档
  2. 安装Sendmail(工作正常!)

我有一个带有LAMP堆栈的VMware映像.为了发送电子邮件,我最终决定:

  • 安装Sendmail
  • 使用我的ISP的smtp(因为它只是一个开发箱).

对于sendmail部分,您可以按照以下步骤操作: http://www.geoffke.be/nieuws /13/

重要:某些虚拟主机可能仅使用稳定的软件包,这意味着您可以拥有...早于2.9的Postfix !!!范例: http://packages.debian.org/search?keywords=postfix

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\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "From: example.com <info@example.com>\r\n";
$headers .= "Reply-To: donotreply@example.com\r\n";
mail('me@example.com', '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\r\n"; mail header.
  2. Ensure I end my headers with only "\n" instead of "\r\n".

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

解决方案

You have 2 solutions:

  1. Upgrade Postfix to +2.9 which has "sendmail_fix_line_endings" (finally!!!) See: Postfix documentation
  2. Install Sendmail (working fine!)

I have a VMware image with a LAMP stack. In order to send email, I finally decided to:

  • install Sendmail
  • use the smtp of my ISP (as it is only a dev box).

For the sendmail part, you can follow this: http://www.geoffke.be/nieuws/13/

IMPORTANT: Some webhosters may use only stable packages which means you can have... a Postfix older than 2.9!!! Exemple: http://packages.debian.org/search?keywords=postfix

这篇关于PHP邮件格式问题-为什么CRLF标头行结尾会破坏Outlook中的HTML电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆