Search code examples
phphtmlphpmailer

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->IsHTML(true);
    $mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png'); 

    //footer
    $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/>
                    NamDimes<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?


Solution

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

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

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

    EDIT

    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