如何在电子邮件中嵌入图像 [英] How to embed images in email
问题描述
我需要在电子邮件中嵌入图像。我如何做?
I need to embed an image in e-mail. How do I do it?
我不想使用第三方工具,也没有对语言具体的答案感兴趣(但是,如果您想知道)
I do not want to use third party tool, nor am I interested in language specific answer (but it is PHP, in case you are wondering).
我只对生成的电子邮件正文的格式感兴趣。
I am merely interested in format of resulting e-mail body.
推荐答案
如你所知,所有通过电子邮件传递的内容都必须进行文字化。
As you are aware, everything passed as email message has to be textualized.
- 您必须创建一个包含multipart / mime消息的电子邮件。
- 如果要添加一个物理图像,图像必须是基础64编码并分配一个Content-ID(cid)。如果它是一个URL,那么
< img />
标签就足够了(映像的URL必须链接到源代码)。
- You must create an email with a multipart/mime message.
- If you're adding a physical image, the image must be base 64 encoded and assigned a Content-ID (cid). If it's an URL, then the
<img />
tag is sufficient (the url of the image must be linked to a Source ID).
典型的电子邮件示例如下所示:
A Typical email example will look like this:
From: foo1atbar.net
To: foo2atbar.net
Subject: A simple example
Mime-Version: 1.0
Content-Type: multipart/related; boundary="boundary-example"; type="text/html"
--boundary-example
Content-Type: text/html; charset="US-ASCII"
... text of the HTML document, which might contain a URI
referencing a resource in another body part, for example
through a statement such as:
<IMG SRC="cid:foo4atfoo1atbar.net" ALT="IETF logo">
--boundary-example
Content-Location: CID:somethingatelse ; this header is disregarded
Content-ID: <foo4atfoo1atbar.net>
Content-Type: IMAGE/GIF
Content-Transfer-Encoding: BASE64
R0lGODlhGAGgAPEAAP/////ZRaCgoAAAACH+PUNv
cHlyaWdodCAoQykgMTk5LiBVbmF1dGhvcml6ZWQgZHV
wbGljYXRpb24gcHJvaGliaXRlZC4A etc...
--boundary-example--
请参阅 Content-ID:< foo4atfoo1atbar.net>
ID与< IMG>
code> SRC = CID:foo4atfoo1atbar.net。这样,客户端浏览器会将您的图像呈现为内容,而不是附件。
As you can see, the Content-ID: <foo4atfoo1atbar.net>
ID is matched to the <IMG>
at SRC="cid:foo4atfoo1atbar.net"
. That way, the client browser will render your image as a content and not as an attachement.
希望这有帮助。
这篇关于如何在电子邮件中嵌入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!