企业模板html图片不显示不出来,HTML邮件中的嵌入图像显示在模板中而不是模板中...

我正在用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';

}

}

}

这将在我的模板中呈现图像:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值