我使用的PHP地 mail() 能发送HTML电子邮件和具有格式问题在用户最常见的电子邮件的客户 Outlook2007年 (此外,一些其他客户的电子邮件)-all html tags暴露,所以它看起来像废话非网络的开发。

我要送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个不同的电子邮件的客户。大部分是确定(例如免费雷鸟、Lotus Notes),但所有的版本不同的前景不确定。

修复的格式问题,我已经做到以下几点:

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

任何人都不会知道我为什么取得更好的结果与HTML电子邮件的时候我做不符合手册?

信息:

  • 我在使用 后缀 版本2.3.3月之5.5.
  • PHP version5.3.2
有帮助吗?

解决方案

你有2个方案:

  1. 升级后缀至+2.9其具有"sendmail_fix_line_endings"(最后!!!) 参见: 后缀文件
  2. 安装Sendmail(工作好了!)

我有一个VMware图像带一个灯堆。为了发送电子邮件,我最后决定:

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

为sendmail的一部分,你可以按照这样的: http://www.geoffke.be/nieuws/13/

重要:一些webhosters可以仅使用稳定的软件包,这意味着你可以...后缀年龄超过2.9!!!Exemple: http://packages.debian.org/search?keywords=postfix

其他提示

如果您使用的后缀<2.9,你可以把 sendmail_path = "tr -d '\r'|sendmail -t -i" 成php.ini。

我怀疑它是我的版本中的后缀版2.3.3是 5岁 也许这是转换LF to CRLF但看到作为我有CRLF已经,我想我是送CRCRLF到邮件的客户。

不幸的是,我不在的情况升级后缀.这样的时刻,我代码转换到使用可配置的可变为行的结局,使得它很容易改变的未来:

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

电子邮件被解释为text/plain而不是旨在html。为此原因是, text/html 是一个多子类型,因此要求边界的声明。

你的代码缺少的 头部边界 宣言:

$message  = get_HTML_email_with_valid_formatting();
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "--$boundary\r\n"."Content-Type: text/html; charset=ISO-8859-1\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);

检查wiki约MIME&多信息:http://en.wikipedia.org/wiki/MIME#Multipart_messages

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top