php - 在 Thunderbird 中使用 Content-ID 和 cid 嵌入电子邮件图像

标签 php email html-email email-attachments thunderbird

我在 PHP 应用程序中生成电子邮件,将多个文件附加到 HTML 电子邮件中。一些文件是 Excel 电子表格,一些文件是需要嵌入 HTML 中的公司 Logo ,因此它们默认使用 Content-ID 和 cid 标识符加载以引用附加图像。

据我所知,我的语法是正确的,但是图像永远不会内联加载(但是它们已成功附加)。

From: email@example.com
Reply-To: email@example.com
MIME-Version: 1.0
Content-type: multipart/mixed;boundary="d0f4ad49cc20d19bf96d4adf9322d567"
Message-Id: <20150421165500.0A5488021B@server>
Date: Tue, 21 Apr 2015 12:54:59 -0400 (EDT)

--d0f4ad49cc20d19bf96d4adf9322d567
Content-type: text/html; charset=utf-8
Content-transfer-encoding: 8bit

<html>
    Html message goes here, followed by email.<br/>
    <img src="cid:mylogo" />
</html>
--d0f4ad49cc20d19bf96d4adf9322d567
Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; name=excelsheet.xlsx
Content-Description: excelsheet.xlsx
Content-Disposition: attachment;
 filename="excelsheet.xlsx"; size=24712;
Content-transfer-encoding:base64

[base64 encoded string goes here.]

--b19e863e2cf66b40db1d138b7009010c
Content-Type: image/jpeg;
 name="mylogo.jpg"
Content-transfer-encoding:base64
Content-ID: <mylogo>
Content-Disposition: inline;
 filename="mylogo.jpg"; size=7579;

[base64 encoded string goes here.]

--b19e863e2cf66b40db1d138b7009010c--

任何人都可以看到图像无法按预期嵌入的明显原因吗?

编辑

请注意,此行为并非适用于所有电子邮件客户端。到目前为止,仅在 Thunderbird 中注意到。

最佳答案

我注意到两个问题:

  • MIME 边界不一致。第一个附件是 d0f4ad49cc20d19bf96d4adf9322d567然后 b19e863e2cf66b40db1d138b7009010c用来。因此,从技术上讲,第二个附件是第一个附件的“一部分”。
    如果替换所有 b19e863e2cf66b40db1d138b7009010c通过 d0f4ad49cc20d19bf96d4adf9322d567 Thunderbird 正确识别图像附件。
  • 使用multipart/related而不是 multipart/mixed . (见 RFC2387)

    A multipart/related is used to indicate that each message part is a component of an aggregate whole. It is for compound objects consisting of several inter-related components - proper display cannot be achieved by individually displaying the constituent parts. The message consists of a root part (by default, the first) which reference other parts inline, which may in turn reference other parts. Message parts are commonly referenced by the "Content-ID" part header. (see Wikipedia entry for MIME multipart/related)


  • 关于php - 在 Thunderbird 中使用 Content-ID 和 cid 嵌入电子邮件图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29779316/

    相关文章:

    php - 由于查询导致页面加载缓慢

    email - 网络::SMTPAuthenticationError

    html - 将表并排放置而不使用 'float'

    php - preg_match() 期望参数 2 为字符串,在 CakePHP 中给出错误的对象

    python - 在 Python 中将表作为电子邮件正文(而不是附件)发送

    html - HTML 电子邮件的填充问题

    php - Ajax 只在第一次工作

    php - BDD 测试有太多后台作业?

    php - 从 PHP、JSON Highcharts 获取数据?

    PHP 基于任意搜索查询在电子邮件数据库中搜索电子邮件地址和正文内容