Search code examples
phpemailphpmailer

PhpMailer not working with html


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->IsSMTP();
            $mail->SMTPAuth = true;
            $mail->SMTPSecure = 'ssl';
            $mail->Host = "smtp.gmail.com";
            $mail->Port = 465;

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


                $mail->setFrom($from);
                $mail->addAddress($to);

            $mail->Subject = $subject;
            $mail->Body =$body;
            $mail->IsHTML(true); 

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

                return 0;
            }

Solution

  • 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.