HTML 封电子邮件作为 HTML 代码发送
HTML emails sending as HTML code
我正在使用亚马逊 AWS SES。这是我发送电子邮件的方式:
$request = array();
$request['Source'] = $row['emailfromname'] . " <{$verifyemail[0]}>";
$request['Destination']['ToAddresses'] = $to;
$request['Message']['Subject']['Data'] = $row['emailsubject'];
$request['Message']['Body']['Html']['Data'] = $row['emailbody'];
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
...
所以这很基础。
我的问题是某些电子邮件以 HTML 发送。这是违规者的示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p><span style="font-family: Calibri, sans-serif; line-height: 11pt; font-size: 11pt; color: #333333;">Hi Name,</span></p>
<hr><span style="font-size:11pt;font-family:'Calibri',sans-serif"><b>From:</b> sender@sender.com.au<br><b>Sent:</b> Thursday, 9 March 2017 10:51 AM<br><b>To:</b> receiver@receiver.com.au<br><b>Subject:</b> Enquiry for ID: 98419081886, 123 Fake Street,
Docklands, Vic 3008, Listing Agent Leasing Consultant</span><br><br><div id="message" style="width: 600px; margin: 0 auto;">
<h1 class="header">
<img src="http://www.test.com/logo.png" style="border: 0; width: 258px;"><div class="header-separator" style="height: 4px; background-color: #e4002b; width: 100%; margin-top: 17px;"></div>
</h1>
<p style="margin: 0;">You have received a new enquiry for</p>
<br><p style="margin: 0;"> id: 98419081886</p>
<div class="footer" style="margin-top: 1em; padding: 5px; background: #999999; color: #fff;">
Message sent from <a href="http://www.test.com.au" style="color: #fff;">www.test.com.au</a> </div>
</div></body></html>
它以纯文本形式作为 HTML 代码发送,其中包含奇怪的 header 信息。这是我收到的 Outlook 2010 电子邮件:
Docklands, Vic 3008, Listing Agent Leasing Consultant
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p><span style="font-family: Calibri, sans-serif; line-height: 11pt; font-size: 11pt; color: #333333;">Hi Name,</span></p> <hr><span style="font-size:11pt;font-family:'Calibri',sans-serif"><b>From:</b> sender@sender.com.au<br><b>Sent:</b> Thursday, 9 March 2017 10:51 AM<br><b>To:</b> receiver@receiver.com.au<br><b>Subject:</b> Enquiry for ID: 98419081886, 123 Fake Street, Docklands, Vic 3008, Listing Agent Leasing Consultant</span><br><br><div id="message" style="width: 600px; margin: 0 auto;">
<h1 class="header">
<img src="http://www.test.com/logo.png" style="border: 0; width: 258px;"><div class="header-separator" style="height: 4px; background-color: #e4002b; width: 100%; margin-top: 17px;"></div>
</h1>
<p style="margin: 0;">You have received a new enquiry for</p>
<br><p style="margin: 0;"> id: 98419081886</p>
<div class="footer" style="margin-top: 1em; padding: 5px; background: #999999; color: #fff;">
Message sent from <a href="http://www.test.com.au" style="color: #fff;">www.test.com.au</a> </div>
</div></body></html>
然而,真正让我感到困惑的是,其他非常相似的电子邮件发送时完全没有问题!
我猜输出的第一行是 Docklands, VIC 3008 ...
,但即使我删除了 line-break、space 和逗号(所以它读取 123 Fake StreetDocklands
),输出剧照以 Docklands...
开始,包括开头的 space!
感到羞怯和恼火...在让自己陷入困境之后,我发现了我的问题。太琐碎了,我打算删除这个问题,但我不会希望它能帮助其他 SES 用户。
我的主题有一个换行符!
我不确定亚马逊如何或为何让这导致电子邮件正文出现问题,但确实如此。
我正在使用亚马逊 AWS SES。这是我发送电子邮件的方式:
$request = array();
$request['Source'] = $row['emailfromname'] . " <{$verifyemail[0]}>";
$request['Destination']['ToAddresses'] = $to;
$request['Message']['Subject']['Data'] = $row['emailsubject'];
$request['Message']['Body']['Html']['Data'] = $row['emailbody'];
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
...
所以这很基础。
我的问题是某些电子邮件以 HTML 发送。这是违规者的示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p><span style="font-family: Calibri, sans-serif; line-height: 11pt; font-size: 11pt; color: #333333;">Hi Name,</span></p>
<hr><span style="font-size:11pt;font-family:'Calibri',sans-serif"><b>From:</b> sender@sender.com.au<br><b>Sent:</b> Thursday, 9 March 2017 10:51 AM<br><b>To:</b> receiver@receiver.com.au<br><b>Subject:</b> Enquiry for ID: 98419081886, 123 Fake Street,
Docklands, Vic 3008, Listing Agent Leasing Consultant</span><br><br><div id="message" style="width: 600px; margin: 0 auto;">
<h1 class="header">
<img src="http://www.test.com/logo.png" style="border: 0; width: 258px;"><div class="header-separator" style="height: 4px; background-color: #e4002b; width: 100%; margin-top: 17px;"></div>
</h1>
<p style="margin: 0;">You have received a new enquiry for</p>
<br><p style="margin: 0;"> id: 98419081886</p>
<div class="footer" style="margin-top: 1em; padding: 5px; background: #999999; color: #fff;">
Message sent from <a href="http://www.test.com.au" style="color: #fff;">www.test.com.au</a> </div>
</div></body></html>
它以纯文本形式作为 HTML 代码发送,其中包含奇怪的 header 信息。这是我收到的 Outlook 2010 电子邮件:
Docklands, Vic 3008, Listing Agent Leasing Consultant
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p><span style="font-family: Calibri, sans-serif; line-height: 11pt; font-size: 11pt; color: #333333;">Hi Name,</span></p> <hr><span style="font-size:11pt;font-family:'Calibri',sans-serif"><b>From:</b> sender@sender.com.au<br><b>Sent:</b> Thursday, 9 March 2017 10:51 AM<br><b>To:</b> receiver@receiver.com.au<br><b>Subject:</b> Enquiry for ID: 98419081886, 123 Fake Street, Docklands, Vic 3008, Listing Agent Leasing Consultant</span><br><br><div id="message" style="width: 600px; margin: 0 auto;">
<h1 class="header">
<img src="http://www.test.com/logo.png" style="border: 0; width: 258px;"><div class="header-separator" style="height: 4px; background-color: #e4002b; width: 100%; margin-top: 17px;"></div>
</h1>
<p style="margin: 0;">You have received a new enquiry for</p>
<br><p style="margin: 0;"> id: 98419081886</p>
<div class="footer" style="margin-top: 1em; padding: 5px; background: #999999; color: #fff;">
Message sent from <a href="http://www.test.com.au" style="color: #fff;">www.test.com.au</a> </div>
</div></body></html>
然而,真正让我感到困惑的是,其他非常相似的电子邮件发送时完全没有问题!
我猜输出的第一行是 Docklands, VIC 3008 ...
,但即使我删除了 line-break、space 和逗号(所以它读取 123 Fake StreetDocklands
),输出剧照以 Docklands...
开始,包括开头的 space!
感到羞怯和恼火...在让自己陷入困境之后,我发现了我的问题。太琐碎了,我打算删除这个问题,但我不会希望它能帮助其他 SES 用户。
我的主题有一个换行符!
我不确定亚马逊如何或为何让这导致电子邮件正文出现问题,但确实如此。