编程语言
首页 > 编程语言> > Microsoft Exchange不会将PHPmailer生成的电子邮件呈现为HTML

Microsoft Exchange不会将PHPmailer生成的电子邮件呈现为HTML

作者:互联网

这个问题困扰了我好几个星期了.我有一个脚本,可以在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();

解决方法:

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

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

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

标签:email,exchange-server,phpmailer,html,php
来源: https://codeday.me/bug/20191121/2054341.html