Adding embedded images within mail body phpmailer class

∥☆過路亽.° 提交于 2019-12-22 11:18:07

问题


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?


回答1:


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




回答2:


I can confirm that user2189925's answer does work. However, I use the absolute path since the location of the calling script is more likely to change than the location of the image.
e.g.

<img src="C:\folder\images\namDiames.png" />



回答3:


Faced the same problem, then I decided to replace the following

<img src="img/example.jpg"

with

<img src= "https://mysitename.com/img/example.jpg">

and it worked.




回答4:


just give path of your image to the mail body eg: (img src="../images/cat.jpeg) it will definately work



来源:https://stackoverflow.com/questions/15518703/adding-embedded-images-within-mail-body-phpmailer-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!