从 SwiftMailer 到 PHPMailer 的转换 [重复]

Posted

技术标签:

【中文标题】从 SwiftMailer 到 PHPMailer 的转换 [重复]【英文标题】:Conversion from SwiftMailer to PHPMailer [duplicate] 【发布时间】:2021-10-14 07:54:47 【问题描述】:

我正在从 SwiftMailer 退回到 phpMailer。

在 SwiftMailer 中,每当您想将图像合并到 html 电子邮件中时,您必须在实例化的 Swift_Message 对象中为每个图像插入以下代码行:

$email_msg->embed( Swift_Image::fromPath( $image_path ) );

我需要在 PHPMailer 中做类似的事情吗?如果是这样,我该怎么做?

我在解决此问题的文档中找不到任何内容。

谢谢!

【问题讨论】:

【参考方案1】:

PHPMailer 中的等价物是addEmbeddedImage。这里有更多可用的选项,但重要的用法是:

$mail->addEmbeddedImage($image_path, 'my_image');

这会从路径加载图像,并将其与内容标识符(cid)相关联,然后您的消息正文可以通过以下方式引用它:

<img src="cid:my_image">

这种方法依赖于包含可以映射到 MIME 类型的文件扩展名(例如 .png)的图像路径。如果你没有,你可以自己设置 MIME 类型以及编码方法,它几乎总是 base64。

【讨论】:

以上是关于从 SwiftMailer 到 PHPMailer 的转换 [重复]的主要内容,如果未能解决你的问题,请参考以下文章