PHPMailer和AddEmbeddedImage导致邮件内容为空
每当我尝试嵌入图像时,GMail都会显示空白内容,而不是HTML消息 代码如下:PHPMailer和AddEmbeddedImage导致邮件内容为空,php,phpmailer,Php,Phpmailer,每当我尝试嵌入图像时,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
$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!';
$mail->AddEmbeddedImage($filesDir./emails/img/community-i.png),“community-i”);
$mail->Body='Embedded Image:Here is a Image!';
但同样的问题是,空白内容(如果我对AddEmbeddedImage函数调用进行注释,将显示内容,并且如预期的那样,将显示alt标记,而不是图像)
我在Gmail、Yahoo和Hotmail上进行了测试,所有地址都有相同的问题。确保您的PHPMailer库是最新的 其他地址和电子邮件地址会发生什么情况?电子邮件内容中是否使用了图像?你说的“带地址的电子邮件地址”是什么意思?抱歉,请将其发送到非gmail地址。Hotmail和Yahoo也存在同样的问题(当我对AddEmbeddedImage函数进行注释时,它起作用,图像被替换为ALT文本)。下一步,请尝试图像的完整服务器路径