【发布时间】: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->Mailer = 'smtp'; -
由于没有一个答案能解决我的问题,所以不能将赏金奖励给任何人
标签: php html email exchange-server phpmailer