PHPmailer AddEmbeddedImage failed to embed Image

北慕城南 提交于 2021-01-27 18:48:36

问题


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>";

回答1:


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');


来源:https://stackoverflow.com/questions/45920800/phpmailer-addembeddedimage-failed-to-embed-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!