php 在邮件正文 phpmailer 类中添加嵌入的图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15518703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding embedded images within mail body phpmailer class
提问by Lappies
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?
我已经设置了其他所有内容,包括地址,邮件被发送,我想嵌入正文的徽标图像作为附件附加,有人知道为什么吗?
回答by JoDev
Don't use $mailer->AddEmbeddedImage, but directly add
不用$mailer->AddEmbeddedImage,直接加
<img src="http://.../images/namDiams.png" />instead.
<img src="http://.../images/namDiams.png" />反而。
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
这里的另一个话题
回答by NathanW
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.
我可以确认 user2189925 的回答确实有效。但是,我使用绝对路径,因为调用脚本的位置比图像的位置更有可能改变。
例如
<img src="C:\folder\images\namDiames.png" />
回答by Naveen
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.
它奏效了。
回答by Sahil Bhatia
just give path of your image to the mail body eg: (img src="../images/cat.jpeg) it will definately work
只需将您的图像路径提供给邮件正文,例如:(img src="../images/cat.jpeg) 它肯定会起作用

