Both Outlook and Thunderbird (2.0.0.21) display it correctly when there is no embedded image. (Both display HTML)
When I try to embed an image Thunderbird falls back to showing the plain text body and the image and the HTML part appear as separate attachments (The HTML body is called Part 1.2).
I know TB can display embedded images because if I compose a message in Outlook and send to TB it displays fine.
One difference seems to be that messages authored in Outlook or TB wrap the name and filename headers in quotes (when viewing the message source). Swift has no quotes around these values.
e.g
Code: Select all
Content-Type: image/png;
name="logo.png"
Content-Transfer-Encoding: base64
Content-ID: <part1.00070101.09080800@example.com>
Content-Disposition: inline;
filename="logo.png"
Thanks,
Code: Select all
<?php
require 'Swift-4.0.3/lib/swift_required.php';
//Messsage
$msg = Swift_Message::newInstance();
$msg -> setSubject('See my image');
$msg -> setFrom(array('swift@example.com'));
$msg -> setTo(array('thunderbird@example.com'=>'Thunderbird Client'));
$msg -> setBody("This is the plain text you'll see when I try and embed an image.");
//Image to embed
$cid = $msg->embed(Swift_Image::fromPath('logo.png'));
$img = '<p><img src="' . $cid . '" alt="Awesome Logo" width="120" height="36"></p>';
// HTML body
$msg -> addPart(
"<h1>See my logo</h1>" .
"<p>Outlook works, Thunderbird will fall back to plain text and show the " .
"HTML body (as Part 1.2) and the image as attachments</p>" .
$img,
'text/html'
);
//Transport and Mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
if($mailer->send($msg)) {
echo "Message Sent";
}