htmlメールに埋め込まれた画像は、テンプレートの代わりに添付されています
-
30-10-2019 - |
質問
swiftmailerでHTMLメールを送信しています。それはすべて非常にうまく機能し、私のHTMLメールはすべてのクライアントでうまく表示されています。電子メールテンプレートの構築に関する知識があります。それほどではないことを自分で送る...
問題はGmailとhotmailに存在します。画像が表示されていません。たとえば、Thunderbirdではうまく表示されています... Gmailは私の画像を空白にしており、添付ファイルとして追加します(誕生日の写真を送っているように、メールの下部に)。
何か案は?
次のコードがあります。
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';
}
}
}
ここで私のテンプレートで画像をレンダリングします:
<td id="head" height="80" width="640" colspan="3" valign="top" align="left">
<image src="[*imgsrc*]" width="140" height="80" alt="xxx"/>
</td>
正しい解決策はありません
所属していません StackOverflow