【问题标题】:Microsoft Exchange doesn't render email generated by PHPmailer as HTMLMicrosoft Exchange 不会将 PHPmailer 生成的电子邮件呈现为 HTML
【发布时间】:2014-06-21 05:30:45
【问题描述】:

这个问题困扰了我好几个星期。我有一个脚本,它在 PHPmailer 的帮助下将带有 xls 附件的 html 电子邮件发送给多个收件人。一年多来一直运行良好。最近,来自同一家公司的两个收件人使用 Microsoft Exchange 作为他们的电子邮件客户端,以文本形式收到了这封电子邮件。以下是他们收到的示例电子邮件:

--b1_dbc2cccc876da210fd56ae7a2601e692
Content-Type: multipart/alternative;
        boundary="b2_dbc2cccc876da210fd56ae7a2601e692"

--b2_dbc2cccc876da210fd56ae7a2601e692
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

To view the message, please use an HTML compatible email viewer!


--b2_dbc2cccc876da210fd56ae7a2601e692
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

....................................
the email body html code in this block
....................................


--b2_dbc2cccc876da210fd56ae7a2601e692--

--b1_dbc2cccc876da210fd56ae7a2601e692
Content-Type: application/octet-stream; name="3MShop-NewOrders_07-30AM-05052014.xls"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="3MShop-NewOrders_07-30AM-05052014.xls"

PGgyPjNNU2hvcC1OZXdPcmRlcnMgMDUtMDUtMjAxNCAwNzozMDoxMCBBTSA8L2gyPjxociAvPjx0
YWJsZSBib3JkZXI9MSBjZWxscGFkZGluZz01IGNlbGxzcGFjaW5nPTI+PHRyPjx0ZCBhbGln

MDUgLSBOYXZ5IEJsdWU8L3RkPjx0ZCBhbGlnbj1sZWZ0PjE8L3RkPjwvdHI+PC90YWJsZT4=

....................................
the rest codes of this attachment
....................................

--b1_dbc2cccc876da210fd56ae7a2601e692--

以下是来自其他收件人的示例电子邮件标题

Content-Type: multipart/mixed;
    boundary="b1_dbc2cccc876da210fd56ae7a2601e692"
Sender:  <emocean@cp60.ezyreg.com>
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - cp60.ezyreg.com
X-AntiAbuse: Original Domain - emoceanstudios.com.au
X-AntiAbuse: Originator/Caller UID/GID - [616 500] / [47 12]
X-AntiAbuse: Sender Address Domain - emoceanstudios.com.au
X-Get-Message-Sender-Via: cp60.ezyreg.com: authenticated_id: emocean/from_h
X-Source: 
X-Source-Args: /usr/sbin/proxyexec -q -d -s /var/run/proxyexec/cagefs.sock/socket /bin/cagefs.server 
X-Source-Dir: emoceanstudios.com.au:/public_html/3M-Shop-Scripts

--b1_dbc2cccc876da210fd56ae7a2601e692
Content-Type: multipart/alternative;
    boundary="b2_dbc2cccc876da210fd56ae7a2601e692"

--b2_dbc2cccc876da210fd56ae7a2601e692
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

To view the message, please use an HTML compatible email viewer!


--b2_dbc2cccc876da210fd56ae7a2601e692
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

你可以很容易地看到不同之处在于有问题的没有部分

Content-Type: multipart/mixed;

更奇怪的是,虽然他们的 Microsoft Exchange 无法将 PHPmailer 发送的这封电子邮件呈现为 HTML,但如果我将相同的电子邮件从我的 gmail 转发到他们的 Exchange,他们现在可以正确呈现它。这让我觉得这可能是我的 php 脚本问题。脚本在这里:

$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';


$mail->AddAddress('example@example.com.au', 'example name');
$mail->SetFrom('example@example.com.au', 'example name');

$mail->ContentType = 'text/html';
$mail->IsHTML(true);  

$mail->Subject = 'example subject';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; 

$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment($newOrdersReport);      // attachment

$mail->Send();

【问题讨论】:

  • 尝试不同的 Mailer 属性 /"mail"、"sendmail" 或 "smtp"/。 “mail”在这个类中是默认的(意味着 PHP mail() 函数)。恕我直言,'smtp' 最适合带附件的邮件。 $mail-&gt;Mailer = 'smtp';
  • 由于没有一个答案能解决我的问题,所以不能将赏金奖励给任何人

标签: php html email exchange-server phpmailer


【解决方案1】:

我不是电子邮件专家,但这对我来说并不合适:

--b1_dbc2cccc876da210fd56ae7a2601e692
Content-Type: multipart/alternative;
boundary="b2_dbc2cccc876da210fd56ae7a2601e692"

您已经将 Content-Type 声明为 multipart 并定义了边界,为什么要重复?

【讨论】:

  • 我不明白。我没有将 Content-Type 声明为 multipart,而是将其声明为 html。这是我不明白的事情。请帮忙。
  • 我没有大量使用 PHPmailer 的经验,但是您是否尝试过不声明内容类型? PHPmailer github 页面 (github.com/PHPMailer/PHPMailer) 上显示的示例使用 html 电子邮件,但未设置内容类型。
  • 感谢您的建议。但我无法测试它,因为昨晚问题神奇地消失了,而没有人做任何改变。
【解决方案2】:

请附上收到时的电子邮件源代码。我知道一些旧版本的 Exchange,即没有 SP1 的 2007,据报道会以纯文本形式全面显示 HTML 电子邮件。而且我知道 OWA 对 HTML 电子邮件的支持极差。 OWA 是唯一一个我从来没有让我的电子邮件看起来很好的客户。远不能回答你的问题,但也许有些事情可以激发研究..

另一个想法.. 当通过 PHPmailer 和 Gmail 发送电子邮件时,您应该研究并比较附加到电子邮件的安全性。 SPK 和 DKIM 身份验证以及 SpamAssassin 评分可能会在客户端显示电子邮件的方式中发挥重要作用。如果您没有通过 PHPmailer 对消息进行身份验证,则很可能是触发 Exchange 来限制它的显示方式。

【讨论】:

猜你喜欢
  • 2018-04-22
  • 2014-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-11
  • 2021-06-03
  • 2015-09-25
  • 2016-12-28
相关资源
最近更新 更多