Please excuse my php but, Im using Swiftmailer to send emails from a clients website. They\'ve requested to add an image or two as a signature etc and so looking at the swiftmai
The accepted answer doesn't work (version tested: 5.4.2). (Mine works but could be perfected)
Instead, looking inside the "Original" (Gmail: Show Original) I've found that swiftmailer is omitting adding 2 headers to the attachment, namely:
Content-ID:
X-Attachment-Id: ABC123
ABC123 is the cid we have to put in the body where we want the inline to be showed:
So thanks to this question: I found the way to fix it for swiftmailer (that is even against swiftmailer documentation, but it works while theirs do not)
this is the final (ugly) code:
$attachment = Swift_Attachment::fromPath('image.jpg')->setDisposition('inline');
$attachment->getHeaders()->addTextHeader('Content-ID', '');
$attachment->getHeaders()->addTextHeader('X-Attachment-Id', 'ABC123');
$cid = $message->embed($attachment);
$img = '';
$html = "
$img
";
$message->setBody($html, 'text/html');