有没有办法将图像附加到用PHP创建的html格式的电子邮件消息?
我们需要确保将公司徽标发送给发送给客户的电子邮件,这些客户在阅读电子邮件时可能无法访问互联网(他们显然会将其下载文件).
试试PEAR Mail_Mime包,它可以为您嵌入图像.
您需要使用addHTMLImage()方法并传递内容id(cid),这是一个唯一的文本字符串,您还将在img的src属性中用作cid:
URL.例如:
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 = ''; $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);