Microsoft Exchange doesn't render email generated by PHPmailer as HTML

╄→гoц情女王★ 提交于 2019-12-12 14:14:42

问题


This issue has been annoyed me for weeks. I have a script which sends html email with xls attachmentm to multiple recipients with the help of PHPmailer. It has been working fine for more than one year. Recently two recipients from the same company, who use Microsoft Exchange as their email client, receive this email as text. Following is sample email they receive:

--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--

Following is sample email header from what other recipients get

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

As you can easily see the difference is the problematic one has no section of

Content-Type: multipart/mixed;

What is more strange is while their Microsoft Exchange can not render this email sent from PHPmailer as HTML, if I forward the same email from my gmail to their Exchange, they can now render it correctly. That makes me think it could possibly be my php script problem. Script is here:

$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();

回答1:


I'm not an email expert but this doesn't look right to me:

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

You already declared the Content-Type as multipart and defined the boundary, why is it repeated?




回答2:


Attach the source code of the email as it is when received please. I know some older versions of Exchange, namely 2007 without SP1 have been reported to display HTML emails in plain text across the board. And I know that OWA has extremely poor support for HTML email. OWA is the one and only client that I've never been able to get my emails to look good in. Far from an answer to your question but maybe some things to spark research..

Another thought.. you should look into and compare the security attached to the email when sent via PHPmailer vs Gmail. SPK and DKIM athentication, as well as SpamAssassin scoring could play heavily in how the client displays the email. If you aren't authenticating the message thru PHPmailer it's very likely the triggering Exchange to restrict the way it's displayed.



来源:https://stackoverflow.com/questions/23463576/microsoft-exchange-doesnt-render-email-generated-by-phpmailer-as-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!