这个问题已经困扰我好几个星期了。我有一个脚本,可以在 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: <[email protected] /cdn-cgi/l/email-protection>
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('[email protected] /cdn-cgi/l/email-protection', 'example name');
$mail->SetFrom('[email protected] /cdn-cgi/l/email-protection', '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();