如何在 HTML 电子邮件中嵌入图像?
Duplicates:
I am sending HTML emails using php. I want to use embedded images in the HTML. Is it possible? I have tried lot of different methods, but none are working. Is anyone able to help me please?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要提供图像所在的完整网址
例子:
You need to provide the whole url where your image resides
example:
这并不是一件小事,但经过几次尝试是可行的。
首先,了解如何构建包含正确图像的多部分电子邮件。如果您无法附加图像,它们显然不会出现在电子邮件中。确保将类型设置为
multipart/lated
。其次,了解如何设置 cid 引用,特别是附件的
Content-ID
标头。第三,将它们粘在一起。
在每个步骤中,执行以下操作:
This isn't really trivial, but with a couple of tries doable.
First of all, learn how to build a multipart email, that has the correct images attached to it. If you can't attach the images, they obviously won't be in the email. Make sure to set the type to
multipart/related
.Secondly, find out how to set the cid references, in particular the
Content-ID
header of the attachment.Third, glue it all together.
At each step, do the following:
我发现通过电子邮件发送图像的最佳方法是使用 base64 对其进行编码。
有大量关于此的链接和教程,但这里是 Codeigniter 的代码应该足够了:
I find the best way to send images via email is to encode them with base64.
There are loads of links and tutorials on this but here is this code for Codeigniter should suffice:
这是一种无需担心编码即可获取字符串变量的方法。
如果您有 Mozilla Thunderbird,您可以使用它来为您获取 html 图像代码。
我在这里写了一个小教程,并附有屏幕截图(用于 powershell,但这对此无关紧要):
powershell 电子邮件,其中包含显示红色 x 的 html 图片
再次:
如何在电子邮件中嵌入图像
Here is a way to get a string variable without having to worry about the coding.
If you have Mozilla Thunderbird, you can use it to fetch the html image code for you.
I wrote a little tutorial here, complete with a screenshot (it's for powershell, but that doesn't matter for this):
powershell email with html picture showing red x
And again:
How to embed images in email