使用 PHP 嵌入图像以在电子邮件中使用?
我知道如何将图像作为附件嵌入到电子邮件中,但这并不是我真正想要做的。我想要做的是将图像嵌入到消息中,并在电子邮件本身的正文中使用该图像。是否可以执行此操作或可能以某种方式引用附件以在消息中使用?
我还应该担心这个吗?通过网络上图像的链接加载它们是否更有利?我认为这会减轻我的服务器的一些负载,因此不必在每封打开的电子邮件中直接从我的网站下载它,从而稍微减少带宽。
注意:我并不是在寻找任何电子邮件框架或库等,只是为了找到完成此任务的简单方法。
I know how to embed an image into an email as an attachment, but that's not really what I want to do. What I want to do is embed an image into the message and use that within the body of the email message itself. Is it possible to do this or possibly reference an attached file somehow to be used in the message?
Should I even worry about this? Is it more beneficial to just load them via a link to the image on my network? I was thinking that this would take some load off my server so it didn't have to be downloaded directly from my site in every email message that got opened, thus reducing bandwidth a little.
Note: I'm not looking for any email frameworks or libraries etc, just for a simple way to accomplish this task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
人们会插话告诉你使用 SwiftMailer 或其他一些库。但这并不难。这确实很挑剔,但并不难。下面是我使用的一个函数。我已经对其进行了匿名化处理,希望没有破坏任何东西。在 html 消息(我从另一个函数获得)中,通过以下方式链接到附加图像:
其中
$linkID
与下面函数中使用的值相同。至于是否值得这样做是另一个问题。如果您附加图像,则您将使用带宽来发送消息。也许一次使用所有带宽比分散使用带宽更好?也许不是。
直到我必须向每个收件人发送不同图像时,我才使用附加图像。我不打算在我们的服务器上存储和管理所有这些图像(并尝试对它们进行唯一命名)。
People will chime in to tell you to use SwiftMailer or some other library. But it's not that hard. It's really finicky, but not hard. Below is a function I use. I've anonymized it a bit, and hopefully didn't break anything. In the html message (which I get from another function), link to your attached image this way:
Where
$linkID
is the same value used in the function below.Whether or not it's worthwhile to do is another question. If you attach the image, you're using bandwidth to send the message out. Maybe it's better for you to use the bandwidth all at once rather than spread out? Maybe not.
I didn't use attached images until I had to send out a different image to each recipient. I wasn't about to store and manage all of those images on our server (and try to uniquely name them).
边界、字符集、内容传输编码当然都是可以选择的。 PHPMailer 软件包可以自动为您执行此操作: http:// /www.ustrem.org/en/article-send-mail-using-phpmailer-en/
另请参阅以下位置的图像:http://mailformat.dan.info/body/html.html
Boundary, charset, Content-Transfer-Encoding of course all choosable. The PHPMailer package can do this automatically for you: http://www.ustrem.org/en/article-send-mail-using-phpmailer-en/
See also including images at: http://mailformat.dan.info/body/html.html
我认为唯一的方法是通过 url 引用图像,如下所示:
I think the only way to do this is to reference a image by url like this: