dqw70970 2019-03-23 16:18
浏览 181


I have this PHP code:

for($x = 0; $x < count($obrazy); $x++) 
   $mail->AddEmbeddedImage($obrazy[$x], 'tel'.$x); 

the variable "obrazy" is a table storing path (link to the image) e.g. "obraz/zdjecie.png". I need to do this with a loop because the array of obrazy can have a different size each time. The above loop does not work for me, because when I want to show this image in the mail, nothing is displayed.

$iterator = 0;

while ($row = mysqli_fetch_array($rezultat)) 
         $mail->Body = $mail->Body.'//..........

                <img src="cid:tel'.$iterator.'" style="

                    width: 160px;
                    display: block;
                    float: left;

                "/> //..........


"// ......" means another part of the code that does not matter to the question being asked. The while loop must be because I extract different data from the database. Everything works only the images do not want to be displayed in the email, even if instead of "$iterator" I enter the number. Links to the image contained in the table are RELIABLE for the PHP file.

  • 写回答

1条回答 默认 最新

  • doudang1052 2019-03-23 17:57

    Chances are your path or permissions are wrong; Check the return value from addEmbeddedImage:

    if (!$mail->AddEmbeddedImage($obrazy[$x], 'tel'.$x)) {
      echo 'Failed to attach '. $obrazy[$x];

    It's probably a good idea to turn the path into an absolute one, for example by saying something like __DIR__ . '/' . $obrazy[$x] instead of just the relative path.

    It may be that your current working directory is not where you think it is. Try doing it like this:

    if (!$mail->AddEmbeddedImage(getcwd() . '/' . $obrazy[$x], 'tel'.$x)) {
      echo 'Failed to attach '. getcwd() . '/' . $obrazy[$x];

    Then it will show you the full path of the files it's failing to find, and you can check whether they are correct.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 notepad++ 自动补全提示,如输入汉字"人名",就会出现"张三","李四"
  • ¥15 如何用matlab实现PSO算法与两种智能优化算法在30维和50维问题上的性能比较?
  • ¥15 在qt的QGraphicsView和QGraphicsScene中遇到的问题
  • ¥50 如何完美解决谷歌礼品卡支付不被检测
  • ¥15 nslt的可用模型,或者其他可以进行推理的现有模型
  • ¥15 arduino上连sim900a实现连接mqtt服务器
  • ¥15 vncviewer7.0安装后如何正确注册License许可证,激活使用
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并2
  • ¥66 关于人体营养与饮食规划的线性规划模型
  • ¥15 基于深度学习的快递面单识别系统