【发布时间】:2012-12-25 10:09:08
【问题描述】:
我想用 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 = ".......@gmail.com";
$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 会自动嵌入这些图像?
【问题讨论】:
-
如果符合您的需要,您可以只从外部源加载图像。发送和接收的邮件会更小。
-
这在我的情况下不起作用,因为图像可以在任何阶段移动