PHP将图像附加到电子邮件
发布时间:2020-12-13 22:42:09 所属栏目:PHP教程 来源:网络整理
导读:有没有办法将图像附加到用 PHP创建的html格式的电子邮件消息? 我们需要确保将公司徽标发送给发送给客户的电子邮件,这些客户在阅读电子邮件时可能无法访问互联网(他们显然会将其下载文件). 试试PEAR Mail_Mime套装,可以 embed images for you. 您需要使用add
有没有办法将图像附加到用
PHP创建的html格式的电子邮件消息?
我们需要确保将公司徽标发送给发送给客户的电子邮件,这些客户在阅读电子邮件时可能无法访问互联网(他们显然会将其下载文件).
试试PEAR
Mail_Mime套装,可以
embed images for you.
您需要使用addHTMLImage()方法并传递内容ID(cid),这是一个唯一的文本字符串,您还将在img的src属性中用作cid:URL.例如: include('Mail.php'); include "Mail/mime.php"; $crlf = "rn"; $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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |