我想用PHPMAiler发送简报。该通讯确实有效,但我想知道是否有更好的选择来做到这一点。用HTML电子邮件将PHPMailer嵌入图像的正确方法是什么?
我所拥有的是。
- HTML页面
- 图片
现在我的代码如下
$mail = new PHPMailer();
//Adding the body
$body = file_get_contents('template/index.htm');
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view this message, please use an HTML compatible email viewer!";
$mail->SetFrom('xxxxxxx', 'xxxxxxxxxx');
$address = "[email protected]";
$mail->AddAddress($address, "xxxxxxx");
$mail->AddEmbeddedImage("template/images/bullet_point.gif","1");
$mail->AddEmbeddedImage("template/images/template_1_01.gif","2");
$mail->AddEmbeddedImage("template/images/template_1_03.gif","3");
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
我使用的file_get_contents来获取HTML页面,并AddEmbeddedImage嵌入图片,现在有没有只将HTML页面传递给PHPMailer的方法,PHP Mailer会自动嵌入这些图像?
您可以从外部来源加载图像,如果这符合您的需求。发送和接收的邮件会更小。 – usoban 2009-07-21 12:31:15
这在我的情况下不起作用,因为图像可以在任何阶段移动 – Roland 2009-07-21 12:33:16