doudiza9154 2018-08-16 12:59
浏览 58


I am using PhpMailer class to send emails that contains html,I noticed that if the body on email contain img tags the email not receiving and no errors showing.

Any suggestions?

my code so far:

            $mail = new PHPMailer();
            $mail->SMTPAuth = true;
            $mail->SMTPSecure = 'ssl';
            $mail->Host = "";
            $mail->Port = 465;

            $mail->Username = "myusername";
            $mail->Password = "mypassword";


            $mail->Subject = $subject;
            $mail->Body =$body;

            if ($mail->send()) {
                return 1;
            } else {

                return 0;
  • 写回答

2条回答 默认 最新

  • dongren2128 2018-08-16 13:01

    if you're trying to send it from localhost and read in gmail, it won't work because gmail often creates proxy image links. you need to send image links that direct to internet-accessible location. That's probably it. If you're sending email with links to internet-accessible locations, please attach them to the question and I'll update the answer, too.

    EIDT: after chat with the asker, it was determined the email HTML was missing normal HTML markup: <html><body>ACTUALCONTENT</body></html>, after adding those,image shown up correctly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
  • duandongjin5647 2018-08-16 13:03

    You can use the AddEmbeddedImage method to attach image to your body. So your code should look like this.

    $mail->AddEmbeddedImage($_REQUEST['image_name'], 'ImageName');

    And then in your $body you can use this image

    $body.= "<img src='cid:ImageName' />";



  • ¥15 回答几个问题 关于数据库
  • ¥15 设计程序(标签-STM32|关键词-工作模式)
  • ¥15 51单片机串口通信问题,未完成且要修改
  • ¥15 百鸡问题 c++编程问题(相关搜索:输出数据)
  • ¥30 如何在CMD中设置代理
  • ¥15 我有一块薛定谔的硬盘
  • ¥15 微信小游戏开发2D碰撞检测问题
  • ¥30 MapReduce案例实践(实验过程需要截图加文字)
  • ¥30 链表、二叉树的应用和算法设计
  • ¥15 R语言批量修改csv文件中的某一列