【发布时间】:2015-04-16 03:46:09
【问题描述】:
我正在尝试使用 Swiftmailer 创建一个 html 电子邮件并将图像嵌入到 html 位中。如果我只是用纯文本和 html 版本发送邮件,则 html 版本显示得很好,带有一个损坏的图像图标(当然)。但是,如果我嵌入图像,我只会看到纯文本版本,并且 html 版本和图像都显示为附件。
这种方法看起来有什么问题或突出吗?
电子邮件标题:
Message-ID: <10c312442e249148aa9e87d70681885c@swift.generated>
Date: Sun, 15 Feb 2015 16:04:55 +0100
Subject: Subject here
From: Fastaval <email@xyz.dk>
To: email@example.com
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="_=_swift_v4_1424012695_eef1c60fde0ddd3f8a9ad82190b115f8_=_"
纯文本标题:
--_=_swift_v4_1424012695_eef1c60fde0ddd3f8a9ad82190b115f8_=_
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
HTML 标题:
--_=_swift_v4_1424012695_eef1c60fde0ddd3f8a9ad82190b115f8_=_
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
嵌入图片标题:
--_=_swift_v4_1424012695_eef1c60fde0ddd3f8a9ad82190b115f8_=_
Content-Type: image/jpeg; name=Banner15.jpg
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=Banner15.jpg
Content-ID: <8e75618e41588e7e5b6953f0c319e262@swift.generated>
带有图片的html位:
<div><img alt=3D"banner" src=3D"cid:8e75618e41588e7e5=
b6953f0c319e262@swift.generated"/></div>
我正在生成这样的电子邮件:
$this->_message = Swift_Message::newInstance()
->setFrom($from)
->setTo($to)
->setSubject($subject)
->setBody($message, 'text/plain');
$html = '<div><img alt="banner" src="banner-src"/></div>';
$html = str_replace('banner-src', $this->_message->embed(Swift_Image::fromPath('Banner15.jpg')), $html);
$this->_message->addPart($html, 'text/html');
【问题讨论】:
-
你有想过这个吗?
-
遗憾的是没有 - 我只是链接到文件的在线版本
标签: php gmail swiftmailer