【问题标题】:How to prevent Phpmailer sending embedded image as an attachment?如何防止 Phpmailer 将嵌入图像作为附件发送?
【发布时间】:2021-09-06 07:44:13
【问题描述】:

我正在发送一封带有公司徽标的电子邮件。但是,它将 Base64 文件作为附件发送到 Gmail。徽标在电子邮件中,看起来非常好,但我不明白为什么我将其代码视为附件。

这是我的代码:

$phpmailer->AddStringEmbeddedImage(base64_decode('...'), 'logo', 'logo', 'base64', 'png', 'inline');
.
.
.
<img style="max-width: 140px;" alt="" src="cid:logo">

我有什么问题?谢谢!

【问题讨论】:

    标签: php email phpmailer email-attachments


    【解决方案1】:

    这是因为这就是嵌入图像的工作方式。图片一个附件,它只是被标记为内联,并且有一个内容ID,可以用来从消息的MIME结构中的其他元素中定位它。这在电子邮件客户端中的显示方式会有所不同。有些只会将其显示为 HTML 引用的内容,但其他人也可能会将其显示为附件。但无论你做什么,图像都会成为信息的一部分。如果您指向图像的外部 URL,则它不存在的唯一方法是,但很可能根本不会加载图像。

    我能看出你的唯一错误是你将 MIME 类型设置为png;它应该是image/png。这可能会导致客户端错误处理图像。如果您传递带有扩展名的文件名,the last 3 params 可以省略,因为它们将自动设置或与默认值相同,如下所示:

    $phpmailer->AddStringEmbeddedImage(base64_decode('...'), 'logo', 'logo.png');
    

    【讨论】:

    • $phpmailer-&gt;AddStringEmbeddedImage(base64_decode('...'), 'logo', 'logo.png', 'base64', 'image/png', 'inline'); 你太棒了,我做到了,而且成功了!
    猜你喜欢
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 2020-05-08
    相关资源
    最近更新 更多