如何使用Phpmailer附加图像? [英] How can i attach an image using Phpmailer?

查看:152
本文介绍了如何使用Phpmailer附加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用phphmailer并附加了一个图像,它仅显示像图标一样的图像,而不是图像本身,这是我的代码 你能帮忙吗?

I am using phphmailer and have attached an image, it shows only the image like an icon rather than image itself here is my code could you help.

$mail->AddEmbeddedImage('2.jpg', '2img', '2.jpg');
$mail->Subject  =  "Order Form:  Contact form submitted";
$mail->Body     =  $body . 'img src="../../photo/2img" ;

注意:我在发送此问题时出错,因此我删除了img标记前的html标签.

note: i have dropped html tag befor img as I get error sending this Q.

推荐答案

PHPMailer手册,您可以使用方法AddEmbeddedImage


$mail->AddEmbeddedImage(filename, cid, name);
By using this function with this example's value above, results in this code:
$mail->AddEmbeddedImage('my-photo.jpg', 'my-photo', 'my-photo.jpg '); 

像这样:

$mail->AddEmbeddedImage("rocks.png", "my-attach", "rocks.png");
$mail->Body = 'Embedded Image: <img alt="PHPMailer" src="cid:my-attach"> Here is an image!';

因此cid:my-attach将被替换为电子邮件正文中图像的内联源

so cid:my-attach will be replaced with the inline-source of the image that's inside the email body

这篇关于如何使用Phpmailer附加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆