PHP将图像附加到电子邮件

前端之家收集整理的这篇文章主要介绍了PHP将图像附加到电子邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法将图像附加到用 PHP创建的html格式的电子邮件消息?

我们需要确保将公司徽标发送给发送给客户的电子邮件,这些客户在阅读电子邮件时可能无法访问互联网(他们显然会将其下载文件).@H_502_2@

试试PEAR Mail_Mime套装,可以 embed images for you.

您需要使用addHTMLImage()方法并传递内容ID(cid),这是一个唯一的文本字符串,您还将在img的src属性中用作cid:URL.例如:@H_502_2@

include('Mail.PHP');
include "Mail/mime.PHP";


$crlf = "\r\n";
$hdrs = array( 
        'From' => 'foo@bar.org','Subject' => 'Mail_mime test message' 
        ); 

$mime = new Mail_mime($crlf); 

//attach our image with a unique content id
$cid="mycidstring";
$mime->addHTMLImage("/path/to/myimage.gif","image/gif","",true,$cid);

//now we can use the content id in our message
$html = '<html><body><img src="cid:'.$cid.'"></body></html>';
$text = 'Plain text version of email';

$mime->setTXTBody($text);
$mime->setHTMLBody($html); 

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('person@somewhere.org',$hdrs,$body);
原文链接:https://www.f2er.com/php/133364.html

猜你在找的PHP相关文章