Immagine incorporata nella posta HTML Spettali allegati in modello
-
30-10-2019 - |
Domanda
Sto inviando posta HTML con Swiftmailer. Tutto funziona abbastanza bene, le mie posta HTML si stanno presentando bene in tutti i clienti. Ho abbastanza conoscenza della costruzione di modelli di posta elettronica. Mandandoli da solo non tanto ...
Il problema esiste in Gmail e Hotmail. L'immagine non viene visualizzata. Mostra bene bene in Thunderbird, ad esempio ... Gmail sta lasciando la mia immagine vuota e la aggiunge come un allegato (in fondo alla posta, come se stessi inviando immagini di compleanno ..).
Qualche idea?
Ho il seguente codice:
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';
}
}
}
Il che renderà l'immagine nel mio modello qui:
<td id="head" height="80" width="640" colspan="3" valign="top" align="left">
<image src="[*imgsrc*]" width="140" height="80" alt="xxx"/>
</td>
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow