我有几个简单的表单可以发送仅限html的电子邮件。大多数客户端(Gmail,Lotus Notes 8,hotmail / live,windows live mail,outlook express)收到的电子邮件都很好,但Outlook 2007却没有。
代码如下所示:
$data="
<html>
<body>
<strong><u>$sub</u></strong><br><br>
<strong>Name:</strong> {$_POST["nombre"]}<br><br>
<strong>Phone:</strong>{$_POST["telefono"]}<br><br>
<strong>Email:</strong> {$_POST["email"]}<br><br>
<strong>Subject:</strong> {$_POST["asunto"]}<br><br>
<strong>Question:</strong> {$_POST["consulta"]}</strong>
</body>
</html>";
$header = "Reply-To: $from\r\n";
$header .= "From: \"".$_POST["nombre"]."\" <$from>\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$enviado = mail($destino,$sub,$data,$header);
($from
是验证消息的唯一部分)
客户收到的消息如下所示:
Content-Type: text/html; charset=iso-8859-1
From: Consulta de "Boss" <boss@myfirm.com>
Reply-To: boss@myfirm.com
X-Mailer: PHP/
<strong><u>Solicitud de envío de recetas -
CLIENT</u></strong><br><br><strong>Nombre y Apellido:</strong>
Boss<br><br><strong>Email:</strong>
boss@myfirm.com<br><br><br>
有什么想法吗?
答案 0 :(得分:8)
您是否尝试过发送多部分电子邮件,在执行此操作时我们从未遇到过outlook 2k3和2k7的问题(除了糟糕的HTML呈现)
<?php
$header = "From: Sender <sen...@domain.org>\r\n";
$header .= "Reply-to: Sender <blabla...@domain.net>\r\n";
$header .= "X-Mailer: Our Php\r\n";
$boundary = "==String_Boundary_x" .md5(time()). "x\r\n";
$boundary2 = "==String_Boundary2_y" .md5(time()). "y\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/related;\r\n";
$header .= " type="multipart/alternative";\r\n";
$header .= " boundary="$boundary";\r\n";
$message = "If you read this, your email client doesn't support MIME\r\n";
$message .= "--$boundary\r\n";
$message .= "Content-Type: multipart/alternative;\r\n";
$message .= " boundary="$boundary2";\r\n";
$message .= "--$boundary2\r\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "Alternative message in plain text format.\r\n";
$message .= "--$boundary2\r\n";
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "<html><body><p>HTML formatted message</p></body></html>";
你可以用你想要的任何东西来代替边界,但它们必须是唯一的。
为了在php中发送更强大,更灵活的电子邮件,我建议使用SwiftMailer
编辑:由于Outlook 2007有一个非常愚蠢的HTML渲染器,你也可以尝试修复你的标记,在你的例子中永远不会打开</font>
,如果它是真正的邮件或有问题的拼写错误就不知道。< / p>
答案 1 :(得分:3)
我有一个非常类似的问题,尝试从你的返回中删除/ r并仅使用/ n。 Outlook andd hotmail与/ r / n有问题。
答案 2 :(得分:2)
我确认Exchange janmoesen 的共享体验。 不得不将标题中的CRLF更改为LF,然后它就开始工作了。
(再次感谢微软,让我的工作时间延长了40%。
也非常感谢janmoesen指出这一点!此搜索已结束。)
答案 3 :(得分:2)
我在Outlook 2007中遇到了同样的问题。
答案很简单:用 \ n
替换 \ r \ n答案 4 :(得分:1)
如果邮件是HTML格式,则需要将其标识为:
$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
答案 5 :(得分:1)
我总是运用MIME编码的HTML邮件。即使只有一个部分,我通常使用multipart / mixed并显式设置内容类型(text / html)。我对PHP不太熟悉,但PEAR::Mail_Mime
包看起来像是候选人。
Outlook应该没有问题处理它。 (emphisis on 不应该)。
答案 6 :(得分:1)
我在使用Exchange(不仅仅是Outlook)和CRLF的标题中遇到了类似结果的问题。基本上,我们发送邮件(在Debian上使用带有Postfix的PHP)和CRLF分隔的标题,这些标题在到达时会在Exchange中被破坏。当我将\r\n
更改为\n
时,问题就消失了。 (“RFC被诅咒!”,嗯?)
答案 7 :(得分:-1)