编程语言
首页 > 编程语言> > php-在Thunderbird中使用Content-ID和cid嵌入电子邮件图像

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

作者:互联网

我在将多个文件附加到HTML电子邮件的PHP应用程序中生成电子邮件.其中一些文件是Excel电子表格,一些文件是公司徽标,需要将其嵌入HTML中,因此默认情况下会使用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会正确识别图像附件.
>使用分段/相关而不是分段/混合. (请参阅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 07001)

标签:email-attachments,php,email,html-email,thunderbird
来源: https://codeday.me/bug/20191012/1899786.html