【发布时间】:2010-09-09 10:09:00
【问题描述】:
我正在做一些测试,到目前为止我尝试了两种解决方案:
第一个在headers里面发送消息(mail()函数的message参数为空)[]
$boundary = "nextPart";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: ".$from_name." <".$from.">\r\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n";
//Html
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= $html;
//Text
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= $text;
第二个是这个:http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment(设置标题并在消息中发送)
它们都不能正常工作(第一个根本不工作,第二个在 gmail 中工作,但它不是格式正确的电子邮件,有些客户端无法处理)。 剖析 php mailer (http://phpmailer.worxware.com/index.php?pg=phpmailer) 的代码,我发现它甚至没有尝试发送多部分电子邮件。
所以我想知道是否可以使用 php 邮件功能发送格式正确的多部分电子邮件。
谢谢
附言我知道并使用梨邮件,我只是想了解这个东西。
【问题讨论】:
-
也许突出显示“P.S.” - 否则,“使用 Swiftmailer”的答案将一打 :) 即使您不想在这里使用它们,您可能想查看这些库产生的输出,并检查邮件的源代码是否有差异.
-
您可能只需要在每个 Content-Type 之后添加第二对“\r\n”。并且可能使用 \015\012 来实现 Windows 兼容性。