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
    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
    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' />";
    点赞 评论