Phpmailer image does not appear in Outlook

Asked

Viewed 310 times

0

Good afternoon, everyone,

I made a system that sends emails via Phpmailer from a client table in Mysql. So far so good, works perfectly. The problem occurs when I receive this email in MS Outlook online (outlook.com). The image appears with an icon as if the link to the same was broken or wrong. This also happens on the paid host, where this hosted my site, the image does not appear. How can I get around this problem?

Follow code I did. But note that works well in Gmail.

try{
    $email = $mysql->where('send', 0)->get('cliente');

    // Configutração Server Google Acount RCH - Itaipu
    $mail->IsSMTP();
    $mail->CharSet = 'UTF-8';
    $mail->Host = "smtp.gmail.com";
    $mail->SMTPSecure = "tls";
    $mail->Port = 587;
    $mail->SMTPAuth = true;
    $mail->SMTPKeepAlive = true;
    $mail->Username = EMP_EMAIL;
    $mail->Password = EMP_PASS;
    $mail->From = EMP_EMAIL;
    $mail->FromName = EMP_NAME;
    $mail->WordWrap = 50;
    $mail->IsHTML = true;
    $mail->Subject = NEWS_SUBJECT;

    $mail->AddCustomHeader("X-MSMail-Priority: 1");
    $mail->AddCustomHeader("Priority: 1");
    $mail->AddCustomHeader("Return-Receipt-To: EMP_EMAIL");
    $mail->AddCustomHeader("X-Confirm-Reading-To: EMP_EMAIL");
    $mail->AddCustomHeader("Disposition-Notification-To: EMP_EMAIL");
    $mail->ConfirmReadingTo = EMP_EMAIL;

    $message = "<html>";
    $message .= "<body>";
    $message .= "<div>";
    $message .= "<img src='http://acma-development.epizy.com/acma/images/Progressiva_Itaipu.jpg'>";
    $message .= "</div>";
    $message .= "</body>";
    $message .= "</html>";

    $mail->msgHTML($message, __DIR__);

    for ($i=0; $i < $mysql->num_rows(); $i++) { 

        $mail->addAddress($email[$i]['Email'], sentenceCase($email[$i]['Nome']));

        if(!$mail->send()) {
            echo "Mailer Error (" . str_replace("@", "&#64;", $$email[$i]['Email']) . ")" . $mail->ErrorInfo . '<br />';
        } else {
            echo "Message sent to: " . $email[$i]['Nome'] . '(' . str_replace("@", "&#64;", $email[$i]['Email']) . ')<br />';

            try{
                $mysql->where('ID', $email[$i]['ID'])->update('cliente', array('send' => '1'));
            } catch(Exception $e) {
                echo 'Caught exeception: ', $e->getMessage();
            }
        }
        // Limpa todos os E-mail e anexospara o próximo loop
        $mail->clearAddresses();
        $mail->clearAttachments();
    }
    // Creating the email body to be sent
} catch(phpmailerException $e){
    echo $e->errorMessage();
} catch(Exception $e){
    echo $e->getMessage();
}
  • There would be double quotes inside the img in the src attribute? "<img src=\"http://acma-development.epizy.com/acma/images/Progressiva_Itaipu.jpg\">";

  • Hi Kevin I’ll try but I don’t know if that’s it. But thanks.

  • Hi Kevin, I have tested what I said above and it is still the same. Only in Outlook can not appear the image. In other Webmail everything works well.

  • A little added the image I send in the body of the attached email, everywhere arrives well, only in Outlook that no!!!!

  • Ah, is it just in outlook that it doesn’t work? I hadn’t understood that

  • This post can help you: https://stackoverflow.com/questions/3708153/send-email-with-phpmailer-embed-image-in-body

  • Hi Kevin, I tried to use this function and it didn’t work until I "talked" to the staff via github / phpmailer and with some help I changed my code enough to be more functional, is what is above. But I managed to put to work, in the post below has the solution. Hugs and thanks

Show 2 more comments

1 answer

0

After researching and "listening" what you said here and many tests I managed to solve my question. It follows the code of how I solved and the explanation.

So, as you can see in the above code I was not using an online server (from my site) to fetch an HTTP image and due to the security of Outlook and other Webmail services, this is not allowed, so I switched to my localhost, from where the emails are sent and tb with Kevin’s help, I switched the single quotes to the doubles (from ' to ") in the img tag. I also sent as an attachment, but it didn’t work. Only by making these changes I managed to solve the issue. It’s still working code:

try{
    $email = $mysql->where('send', 0)->get('cliente');

    // Configutração Server Google Acount RCH - Itaipu
    $mail->IsSMTP();
    $mail->CharSet = 'UTF-8';
    $mail->Host = "smtp.gmail.com";
    $mail->SMTPSecure = "tls";
    $mail->Port = 587;
    $mail->SMTPAuth = true;
    $mail->SMTPKeepAlive = true;
    $mail->Username = EMP_EMAIL;
    $mail->Password = EMP_PASS;
    $mail->From = EMP_EMAIL;
    $mail->FromName = EMP_NAME;
    $mail->WordWrap = 50;
    $mail->IsHTML = true;
    $mail->Subject = NEWS_SUBJECT;
    //$mail->addAttachment('images/Progressiva_Itaipu.jpg');

    // Pedido de Confirmação de leitura do E-mail enviado
    // Verificar como enviar para um pag php para alterar DB
    $mail->AddCustomHeader("X-MSMail-Priority: 1");
    $mail->AddCustomHeader("Priority: 1");
    $mail->AddCustomHeader("Return-Receipt-To: " . EMP_EMAIL);
    $mail->AddCustomHeader("X-Confirm-Reading-To: " . EMP_EMAIL);
    $mail->AddCustomHeader("Disposition-Notification-To: " . EMP_EMAIL);
    $mail->ConfirmReadingTo = EMP_EMAIL;

    $message = "<html>";
    $message .= "<body>";
    $message .= "<div>";
    $message .= '<img src="images/Progressiva_Itaipu.jpg" alt="img" />';
    $message .= "</div>";
    $message .= "</body>";
    $message .= "</html>";

    $mail->msgHTML($message, __DIR__);

    for ($i=0; $i < $mysql->num_rows(); $i++) { 

        $mail->addAddress($email[$i]['Email'], sentenceCase($email[$i]['Nome']));

        // Debug
        // $mail->preSend();
        // $bodyMsg = $mail->getSentMIMEMessage();
        // echo $bodyMsg;

        if(!$mail->send()) {
            echo "Mailer Error (" . str_replace("@", "&#64;", $$email[$i]['Email']) . ")" . $mail->ErrorInfo . '<br />';
        } else {
            echo "Message sent to: " . $email[$i]['Nome'] . '(' . str_replace("@", "&#64;", $email[$i]['Email']) . ')<br />';

            try{
                $mysql->where('ID', $email[$i]['ID'])->update('cliente', array('send' => '1'));
            } catch(Exception $e) {
                echo 'Caught exeception: ', $e->getMessage();
            }
        }
        // Limpa todos os E-mail e anexos para o próximo loop
        $mail->clearAddresses();
        $mail->clearAttachments();
    }
} catch(phpmailerException $e){
    echo $e->errorMessage();
} catch(Exception $e){
    echo $e->getMessage();
}

Even with this code, I have the tracker whether or not the client opened the email in question. I still have to see how to get this answer and send it to a php pag to change the BD marking that the Y client opened the email campaign. If you can help me, I will be very grateful and publish here my codes as I did this function.

You can see on this piece of code:

// Pedido de Confirmação de leitura do E-mail enviado
// Verificar como enviar para um pag php para alterar DB
$mail->AddCustomHeader("X-MSMail-Priority: 1");
$mail->AddCustomHeader("Priority: 1");
$mail->AddCustomHeader("Return-Receipt-To: " . EMP_EMAIL);
$mail->AddCustomHeader("X-Confirm-Reading-To: " . EMP_EMAIL);
$mail->AddCustomHeader("Disposition-Notification-To: " . EMP_EMAIL);
$mail->ConfirmReadingTo = EMP_EMAIL;

Thank you all and especially Kevin

Browser other questions tagged

You are not signed in. Login or sign up in order to post.