I'm using Amazon AWS SES. This is how I send emails:
$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');
...
So it's pretty basic.
My problem is that some emails are sending as HTML. Here is an example of an offender:
<!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>
It sends in plain text as HTML code with the weird header info. This is my Outlook 2010 email received:
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>
The thing that's really confused me, however, is that other very similar emails send with no issues at all!
I'm guessing there's a clue in that the first line of the output reads Docklands, VIC 3008 ...
But even if I remove that line-break, the space and the comma (so it reads 123 Fake StreetDocklands
), the output stills starts with Docklands...
including the space at the beginning!
Feeling sheepish and annoyed... After leading myself on a wild goose chase, I found my problem. It's so trivial that I was going to delete this question, but I won't in the hope it helps other SES users.
My subject had a line-break in it!
I'm not sure how or why Amazon lets this cause a problem for the email body, but it does.