Lappies Lappies - 3 years ago 166
HTML Question

Adding embedded images within mail body phpmailer class

Im trying to embed an image within my message body but it ends up as an attachment

$mailer->Subject = APP_NAME . " - " . $name . " send you and Ad : " . $row['name'];
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');

$footer = "Regards<br/><br/>";
$footer .= '<table style="width: 95%">';
$footer .= '<tr>';
$footer .= '<td>';
$footer .= "<strong><span style='font-size: 15px'>NamDimes Team</span></strong><br/>
Contact Number: " . APP_CONTACT . "<br/>
Email: " . APP_EMAIL . "<br/>
Website: " . APP_WEBSITE . "<br/>";
$footer .= '</td>';
$footer .= '<td style="text-align:right">';
$footer .= '<img src=\"cid:logoimg\" />';
$footer .= '</td>';
$footer .= '</tr>';
$footer .= '</table>';

$mailer->Body = $body . $footer;
$mailer->AltBody="This is text only alternative body.";
$mailer->AddAttachment('../' . $row['image_path'], $row['name'] . ".jpg");

i have set everything else, including the addresses, the mail gets send out, logo image that I want embed in the body gets attached as an attachment, anyone know why?

Answer Source

Don't use $mailer->AddEmbeddedImage, but directly add

<img src="http://.../images/namDiams.png" /> instead.

The mail length should be lighter... And it works.


I don't know if it will help you but there is a little mistake here :

$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');

Should be

$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDiames.png');//the last param the second 'a' was missing...

Another topic here

And an explanation here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download