Pregunta

Estoy enviando correos HTML con Swiftmailer. Todo funciona bastante bien, mis correos HTML están apareciendo bien en todos los clientes. Tengo bastante conocimiento de construir plantillas de correo electrónico. Enviándolos yo mismo no tanto ...

El problema existe en Gmail y Hotmail. La imagen no aparece. Se muestra bien en Thunderbird, por ejemplo ... Gmail deja mi imagen en blanco y la agrega como un archivo adjunto (en la parte inferior del correo, como si envié fotos de cumpleaños ...).

¿Algunas ideas?

Tengo el siguiente código:

function deliverMail($subject, $data, $from, $to, $template){
    if($_SERVER['SERVER_ADDR'] !== '::1'){

        if (!is_array($to)){
            $to = array($to);       
        }           
        $from = explode(",", $from);        

        //Create the Transport
        $transport = Swift_SmtpTransport::newInstance('mail.xxx.nl', 25)
          ->setUsername('xxx')
          ->setPassword('xxx');           

        $mailer = Swift_Mailer::newInstance($transport);
        $message = Swift_Message::newInstance($subject);
        $image = $message->embed(Swift_Image::fromPath($_SERVER['DOCUMENT_ROOT'].'/templates/emails/xxx.jpg'));


        // open the file
        $sourcefile     = $_SERVER['DOCUMENT_ROOT'].'/templates/emails/'.$template.'.html.tpl';
        $fh             = fopen($sourcefile, 'r');
        $htmltemplate       = fread($fh, filesize($sourcefile));
        fclose($fh);

        // set the content  
        if($template == 'confirm'){$replaceOld = array("[*code*]", "[*imgsrc*]");}          
        if($template == 'notify'){$replaceOld = array("[*url*]", "[*imgsrc*]");}

        $replaceNew     = array($data, $image);         
        $body           = str_replace($replaceOld, $replaceNew, $htmltemplate);         



        $message->setFrom(array($from[0] => $from[1]))
        ->setTo($to)
        ->setBody($body, 'text/html');


        if (!$mailer->send($message, $failures)){
          return "Failures:";
          return print_r($failures);
        }else{
            return 'success';
        }

    }
}

Que hará la imagen en mi plantilla aquí:

<td id="head" height="80" width="640" colspan="3" valign="top" align="left">
<image src="[*imgsrc*]" width="140" height="80" alt="xxx"/>         
</td>

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top