php 使用 PHPMailer 发送电子邮件 - 在正文中嵌入图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3708153/
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
Send email with PHPMailer - embed image in body
提问by elvispt
I'm trying to send HTML mail, with PHPMailer, with images. The body is loaded from a html file, that contains all the info.
我正在尝试使用 PHPMailer 和图像发送 HTML 邮件。正文从包含所有信息的 html 文件加载。
When sending the mail, the image does not appear in the body, although I even send the image also as an attachment.
发送邮件时,图像不会出现在正文中,尽管我什至将图像也作为附件发送。
HTML <img>
tag points to the same place as the place.
HTML<img>
标记指向与地点相同的地点。
PHP:
PHP:
$mail->AddAttachment('img/2u_cs_mini.jpg');
How can I make the html point to the attachment so the image can be loaded in the body.
如何使 html 指向附件,以便可以将图像加载到正文中。
Looking at the example that comes with PHPMailer I do not notice any difference, and in their case the image does appear.
查看 PHPMailer 附带的示例,我没有注意到任何区别,在他们的情况下,图像确实出现了。
回答by elvispt
I found the answer:
我找到了答案:
$mail->AddEmbeddedImage('img/2u_cs_mini.jpg', 'logo_2u');
and on the <img>
tag put src='cid:logo_2u'
并在<img>
标签上放src='cid:logo_2u'
回答by Marie-Eva BB Volmar
According to PHPMailer Manual, full answer would be :
根据PHPMailer 手册,完整的答案是:
$mail->AddEmbeddedImage(filename, cid, name);
//Example
$mail->AddEmbeddedImage('my-photo.jpg', 'my-photo', 'my-photo.jpg ');
Use Case :
用例:
$mail->AddEmbeddedImage("rocks.png", "my-attach", "rocks.png");
$mail->Body = 'Embedded Image: <img alt="PHPMailer" src="cid:my-attach"> Here is an image!';
If you want to display an image with a remote URL :
如果要显示带有远程 URL 的图像:
$mail->addStringAttachment(file_get_contents("url"), "filename");