php 如何在电子邮件中嵌入图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4312687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to embed images in email
提问by Josef Sábl
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).
我不想使用第三方工具,也不对特定于语言的答案感兴趣(但它是 PHP,以防万一)。
I am merely interested in format of resulting e-mail body.
我只对生成的电子邮件正文的格式感兴趣。
回答by Buhake Sindi
As you are aware, everything passed as email message has to be textualized.
如您所知,作为电子邮件传递的所有内容都必须文本化。
- 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).
- 您必须创建包含多部分 / mime 消息的电子邮件。
- 如果您要添加物理图像,则该图像必须采用 base 64 编码并分配有 Content-ID (cid)。如果是 URL,则
<img />标记就足够了(图像的 URL 必须链接到源 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--
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.
如您所见,Content-ID: <foo4atfoo1atbar.net>ID 与<IMG>at匹配SRC="cid:foo4atfoo1atbar.net"。这样,客户端浏览器会将您的图像呈现为内容而不是附件。
Hope this helps.
希望这可以帮助。
回答by Dan D.
the third way is to base64 encode the image and place it in a data:url
第三种方法是对图像进行base64编码并将其放置在data:url中
example:
例子:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACR0lEQVRYha1XvU4bQRD+bF/JjzEnpUDwCPROywPgB4h0PUWkFEkLposUIYyEU4N5AEpewnkDCiQcjBQpWLiLjk3DrnZnZ3buTv4ae25mZ+Z2Zr7daxljDGpg++Mv978Y5Nhc6+Di5tk9u7/bR3cjY9eOJnMUh3mg5y0roBjk+PF1F+1WCwCCJKTgpz9/ozjMg+ftVQQ/PtrB508f1OAcau8ADW5xfLRTOzgAZMPxTNy+YpDj6vaPGtxPgvpL7QwAtKXts8GqBveT8P1p5YF5x8nlo+n1p6bXn5ov3x9M+fZmjDGRXBXWH5X/Lv4FdqCLaLAmwX1/VKYJtIwJeYDO+dm3PSePJnO8vJbJhqN62hOUJ8QpoD1Au5kmIentr9TobAK04RyJEOazzjV9KokogVRwjvm6652kniYRJUBrTkft5bUEAGyuddzz7noHALBYls5O09skaE+4HdAYruobUz1FVI6qcy7xRFW95A915pzjiTp6zj7za6fB1lay1/Ssfa8/jRiLw/n1k9tizl7TS/aZ3xDakdqUByR/gDcF0qJV8QAXHACy+7v9wGA4ngWLVskDo8kcg4Ot8FpGa8PV0I7MyeWjq53f7Zrer3nyOLYJpJJowgN+g9IExNNQ4vLFskwyJtVrd8JoB7g3b4rz66dIpv7UHqg611xw/0om8QT7XXBx84zheCbKGui2U9n3p/YAlSVyqRqc+kt+mCyWJTSeoMGjOQciOQDXA6kjVTsL6JhpYHtA+wihPaGOWgLqnVACPQua4j8NK7bPLP4+qQAAAABJRU5ErkJggg==" width="32" height="32">
回答by bgmCoder
Here is how to get the code for an embedded image without worrying about any files or base64 statements or mimes (it's still base64, but you don't have to do anything to get it). I originally posted this same answer in this thread, but it may be valuable to repeat it in this one, too.
以下是如何获取嵌入图像的代码,而无需担心任何文件或 base64 语句或 mime(它仍然是 base64,但您无需执行任何操作即可获取它)。我最初在这个帖子中发布了这个相同的答案,但在这个帖子中重复它也可能很有价值。
To do this, you need Mozilla Thunderbird, you can fetch the html code for an image like this:
为此,您需要Mozilla Thunderbird,您可以获取图像的 html 代码,如下所示:
- Copy a bitmap to clipboard.
- Start a new email message.
- Paste the image. (don't save it as a draft!!!)
- Double-click on it to get to the image settings dialogue.
- Look for the "image location" property.
- Fetch the code and wrap it in an image tag, like this:
- 将位图复制到剪贴板。
- 开始新的电子邮件。
- 粘贴图像。(不要将其保存为草稿!!!)
- 双击它进入图像设置对话框。
- 查找“图像位置”属性。
- 获取代码并将其包装在图像标签中,如下所示:
You should end up with a string of text something like this:
你应该得到一串类似这样的文本:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaIAAAGcCAIAAAAUGTPlAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAPbklEQVR4nO3d2ZbixhJAUeku//8vcx/oxphBaMgpIvd+c7uqmqakQ6QkxHq73RaA3tZ13fNlJ5K1yhzQy860fbS/XTIHtHOla9/8jJjMARXV6No332omc0BhLdP27r1pMgeU0bduz16yJnPAVeME7uG5bDIHxTzv7bn3rAG79u7xK/in7+OArNY14QwRom7v/tf7AUASQROw07qu4f6Bjwcsc1BLuC58FDFwD/dHbtEKtWwvWl/aMeAKN27dXpjmoIyLnRqtKaM9ntPWdTXNQRWHRrmhjPzYzjHNQXnnJrsR+jLCYyjONAej6Ht4LmXg7kxzUMahTAx1wiH0udQ9ZA6G0Ct8uQN3Z9EKBeyPxThvCJsh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3l8ZBUDK3i8ZBXDIHJCdzvxnlIDSZ+0HjIDqZ2+K9q5CAzH3lTV2Qg8wBycncZ0Y5SEPmPtA4yETmXmkcJCNz5WkcDEXm/sNVcpCPzP1L4yAlmftD4yArmVsWjYPUZM47uiC52TPn8hFIb+rMaRzMYN7MaRxMYtLMaRzMY8bMaRxMZbrMaRzMZq7MaRxM6J/eD6CRUhfHaRyEM8U0p3Ews/yZ0ziYXOZFa8F3cWkcxJV2mtM44C7nNGehCjxky5whDniRJ3Nl76ekcZBGhswJHLAhduaK3xFT4yCfwGdaNQ7YI+Q0J3DAfsEyV+NzGzQOcguTuUofTKNxkF6AzAkccMW4mav3uYICB1MZMXNVPzhV42A2Y2VO4IDiRsmcwAGV9Mxc1bTdCRzQJ3MCBzTTOnO1A6duwIsWmWswuy0CB3xRJXNtuvYgcMCGYplrnLY7gQN+upq5LnVbBA7Y7VjmekXtmcABh+zKXPe6SRtw2mvmuhftQdqAIv5kbpC6SRtQXP+6SRtQ1XqvjCvdgKzW9+L42FMgk/8DDsgw4HlIEQ0AAAAASUVORK5CYII=" alt="" height="211" width="213">
You can wrap this up into a string variable and place this absolutely anywhere that you would present an html email message - even in your email signatures. The advantage is that there are no attachments, and there are no links. (this code will display a lizard)
您可以将其包装到一个字符串变量中,并将其绝对放置在您将显示 html 电子邮件消息的任何位置 - 甚至在您的电子邮件签名中。优点是没有附件,也没有链接。(此代码将显示蜥蜴)
A picture is worth a thousand words:

一张图片胜过千言万语:

Incidentally, I did write a program to do all of this for you. It's called BaseImage, and it will create the image code as well as the html for you. Please don't consider this self-promotion; I'm just sharing a solution.
顺便说一句,我确实编写了一个程序来为您完成所有这些工作。 它称为 BaseImage,它将为您创建图像代码和 html。请不要考虑这种自我推销;我只是分享一个解决方案。
回答by Siarhei Kuchuk
Correct way of embedding images into Outlook and avoiding security problems is the next:
将图像嵌入 Outlook 并避免安全问题的正确方法是下一个:
- Use interop for Outlook 2003;
- Create new email and set it save folder;
- Do not use base64 embedding, outlook 2007 does not support it; do not reference files on your disk, they won't be send; do not use word editor inspector because you will get security warnings on some machines;
- Attachment must have png/jpg extension. If it will have for instance tmp extension - Outlook will warn user;
- Pay attention how CID is generated without mapi;
Do not access properties via getters or you will get security warnings on some machines.
public static void PrepareEmail() { var attachFile = Path.Combine( Application.StartupPath, "mySuperImage.png"); // pay attention that image must not contain spaces, because Outlook cannot inline such images Microsoft.Office.Interop.Outlook.Application outlook = null; NameSpace space = null; MAPIFolder folder = null; MailItem mail = null; Attachment attachment = null; try { outlook = new Microsoft.Office.Interop.Outlook.Application(); space = outlook.GetNamespace("MAPI"); space.Logon(null, null, true, true); folder = space.GetDefaultFolder(OlDefaultFolders.olFolderSentMail); mail = (MailItem) outlook.CreateItem(OlItemType.olMailItem); mail.SaveSentMessageFolder = folder; mail.Subject = "Hi Everyone"; mail.Attachments.Add(attachFile, OlAttachmentType.olByValue, 0, Type.Missing); // Last Type.Missing - is for not to show attachment in attachments list. string attachmentId = Path.GetFileName(attachFile); mail.BodyFormat = OlBodyFormat.olFormatHTML; mail.HTMLBody = string.Format("<br/><img src=\'cid:{0}\' />", attachmentId); mail.Display(false); } finally { ReleaseComObject(outlook, space, folder, mail, attachment); } }
- 使用 Outlook 2003 的互操作;
- 创建新电子邮件并将其设置为保存文件夹;
- 不要使用base64嵌入,outlook 2007不支持;不要引用磁盘上的文件,它们不会被发送;不要使用文字编辑器检查器,因为您会在某些机器上收到安全警告;
- 附件必须有 png / jpg 扩展名。如果它将具有例如 tmp 扩展名 - Outlook 将警告用户;
- 注意没有mapi是如何生成CID的;
不要通过 getter 访问属性,否则您将在某些机器上收到安全警告。
public static void PrepareEmail() { var attachFile = Path.Combine( Application.StartupPath, "mySuperImage.png"); // pay attention that image must not contain spaces, because Outlook cannot inline such images Microsoft.Office.Interop.Outlook.Application outlook = null; NameSpace space = null; MAPIFolder folder = null; MailItem mail = null; Attachment attachment = null; try { outlook = new Microsoft.Office.Interop.Outlook.Application(); space = outlook.GetNamespace("MAPI"); space.Logon(null, null, true, true); folder = space.GetDefaultFolder(OlDefaultFolders.olFolderSentMail); mail = (MailItem) outlook.CreateItem(OlItemType.olMailItem); mail.SaveSentMessageFolder = folder; mail.Subject = "Hi Everyone"; mail.Attachments.Add(attachFile, OlAttachmentType.olByValue, 0, Type.Missing); // Last Type.Missing - is for not to show attachment in attachments list. string attachmentId = Path.GetFileName(attachFile); mail.BodyFormat = OlBodyFormat.olFormatHTML; mail.HTMLBody = string.Format("<br/><img src=\'cid:{0}\' />", attachmentId); mail.Display(false); } finally { ReleaseComObject(outlook, space, folder, mail, attachment); } }
回答by Jimmy Obonyo Abor
Actually, there are two ways to include images in email.
实际上,有两种方法可以在电子邮件中包含图像。
The first way ensures that the user will see the image, even if in some cases it's only as an attachment to the message. This method is exactly what we call as “embedding images in email" in daily life.
Essentially, you're attaching the image to the email. The plus side is that, in one way or another, the user is sure to get the image. While the downside is two fold. Firstly, spam filters look for large, embedded images and often give you a higher spam score for embedding images in email (Lots of spammers use images to avoid having the inappropriate content in their emails read by the spam filters.). Secondly, if you pay to send your email by weight or kilobyte, this increases the size of your message. If you're not careful, it can even make your message too big for the parameters of the email provider.
第一种方法确保用户会看到图像,即使在某些情况下它只是作为邮件的附件。这种方法正是我们在日常生活中所说的“在电子邮件中嵌入图像”。
本质上,您是将图像附加到电子邮件中。好处是,以某种方式,用户肯定会得到图像. 虽然缺点有两个。首先,垃圾邮件过滤器会寻找大型嵌入图像,并且通常会给您在电子邮件中嵌入图像的垃圾邮件分数更高(许多垃圾邮件发送者使用图像来避免垃圾邮件阅读其电子邮件中的不当内容过滤器。)其次,如果您按重量或千字节付费发送电子邮件,这会增加您的邮件大小。如果您不小心,它甚至会使您的邮件对于电子邮件提供商的参数来说太大。
The second way to include images (and the far more common way) is the same way that you put an image on a web page. Within the email, you provide a url that is the reference to the image's location on your server, exactly the same way that you would on a web page. This has several benefits. Firstly, you won't get caught for spamming or for your message “weighing” too much because of the image. Secondly, you can make changes to the images after the email has been sent if you find errors in them. On the flip side, your recipient will need to actively turn on image viewing in their email client to see your images.
包含图像的第二种方式(也是更常见的方式)与将图像放在网页上的方式相同。在电子邮件中,您提供一个 url,该 url 是对图像在您的服务器上的位置的引用,与您在网页上的方式完全相同。这有几个好处。首先,您不会因为图片而因垃圾邮件或“权重”过多而被抓到。其次,如果您发现其中有错误,您可以在发送电子邮件后对图像进行更改。另一方面,您的收件人需要在其电子邮件客户端中主动打开图像查看功能才能查看您的图像。
回答by Bob Palmer
Generally I handle this by setting up an HTML formatted SMTP message, with IMG tags pointing to a content server. Just make sure you have both text and HTML versions since some email clients cannot support HTML emails.
通常,我通过设置 HTML 格式的 SMTP 消息来处理此问题,其中 IMG 标记指向内容服务器。只需确保您同时拥有文本和 HTML 版本,因为某些电子邮件客户端不支持 HTML 电子邮件。

