PHPmailer AddEmbeddedImage 无法嵌入图像 [英] PHPmailer AddEmbeddedImage failed to embed Image

查看:41
本文介绍了PHPmailer AddEmbeddedImage 无法嵌入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了两个不同的电子邮件客户端,尝试了 google &stackoverflow 回答了.但未能解决问题.我也测试了本地图片路径,完全没问题.

这里是编码部分:

 $mail->addEmbeddedImage('../img/abc-company-logo.png','logo','abc-company-logo.png');

身体部位:

$mail->Body = "

";

解决方案

问题是 PHPMailer 嵌入了相对于从哪里调用脚本,而不是相对于文档叫进来了.

这意味着通过将 ../img/abc-company-logo.png 传递给 addEmbeddedImage() 将搜索相对于 实际PHPMailer 类文件位置.

您应该将路径更改为绝对文件路径.参见 __DIR____FILE__ 示例 http://php.net/manual/fa/language.constants.predefined.php

例如:

$mail->addEmbeddedImage(dirname(__DIR__) .'/img/abc-company-logo.png','logo','abc-company-logo.png');

I tried two different email client tried google & stackoverflow answered. But failed to solve the issue. I also tested the local image path, it is perfectly ok.

Here is the coding part:

  $mail->addEmbeddedImage('../img/abc-company-
   logo.png','logo','abc-company-logo.png');

Body Part:

$mail->Body    = "<div id='container' style='height:auto;font-
   family:Helvetica;border: 1px solid #CCC;'>
 <div id='header' style='margin: 0 auto; 
  background-color:#0958C3; color:#FFFFFF;
  font-size: 20px;text-align: center;
display:block;
 '>
<img src='cid:logo' alt='Picture Description'/> <br>
<strong>Heading</strong> 
 </div>
</div>";

解决方案

Problem is that PHPMailer embeds inline images relative to where the script is called from, instead of relative to the document called in.

This means by passing ../img/abc-company-logo.png to the addEmbeddedImage() will search for such path relative to the actual PHPMailer class file location.

You should change the path to an absolute file path. See __DIR__, __FILE__ examples here http://php.net/manual/fa/language.constants.predefined.php

For Example:

$mail->addEmbeddedImage(dirname(__DIR__) . '/img/abc-company-logo.png','logo','abc-company-logo.png');

这篇关于PHPmailer AddEmbeddedImage 无法嵌入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆