每当我尝试嵌入图像时,GMail 都会显示空白内容而不是 HTML 消息。
这是代码:
$body = file_get_contents($filesDir . '/emails/wbd.html');
$mail = new \PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = $c['config']['mail.params']['auth'];
$mail->SMTPSecure = $c['config']['mail.params']['secure'];
$mail->Host = $c['config']['mail.params']['host'];
$mail->Port = $c['config']['mail.params']['port'];
$mail->Username = $c['config']['mail.params']['user'];
$mail->Password = $c['config']['mail.params']['password'];
$mail->IsHTML(true);
$mail->SetFrom('example@gmail.com', 'Some name');
$mail->Subject = 'Some subject';
$mail->Body = $body;
$mail->AddEmbeddedImage($filesDir . '/emails/img/community-i.png', 'community-i', 'community-i.png');
$mail->AddAddress($to);
$mail->Send();
如果我删除对AddEmbeddedImage的函数调用,则会发送 HTML 邮件。图像$filesDir 的路径。'/emails/img/community-i.png'是正确的,因为AddEmbeddedImage函数返回 true(并且不正确的路径将显示 HTML 消息)。
我也试试这个:
$mail->AddEmbeddedImage($filesDir . '/emails/img/community-i.png', 'community-i');
$mail->Body = 'Embedded Image: <img alt="PHPMailer" src="cid:community-i"> Here is an image!';
但同样的问题,空白内容(如果我评论AddEmbeddedImage函数调用,内容将显示,并且如预期的那样,而不是图像,出现 alt 标签)。
我在 Gmail、Yahoo 和 Hotmail 上进行了测试,所有地址都存在相同的问题。