dongping4901 2019-06-25 11:44
浏览 40

内联/嵌入式图像附件在PHP Swift Mailer发送的邮件中不可见

I'm sending an image with an attachment that has to shown as inline image.

I can't find out what's wrong with it. I don't remember this being an issue when I coded the mailer

This is the header of of the image inside the email

--_=_swift_1561449240_8047151997d755eb732462545a29a594_=_
Content-Type: image/png; name=logo.png
Content-Transfer-Encoding: base64
X-Attachment-Id: logo
Content-ID: <logo>
Content-Disposition: inline; filename=logo.png

This is the function that sends an email with attachments

public function send(MailInterface $mail, array $attachments = array())
    {
        /* @var SwiftMail $swiftMail */
        $swiftMail = new SwiftMail(
            $mail->getSubject(),
            $mail->getBody(),
            "text/html"
        );

        foreach ($attachments as $contentId => $contentPath) {
            if (null != $contentPath) {

                // prepare content to be send as an attachment
                $attachment = SwiftAttachment::fromPath($contentPath);
                $attachment->setDisposition("inline");
                $attachment->getHeaders()->addTextHeader("Content-ID", "<" . $contentId . ">");
                $attachment->getHeaders()->addTextHeader("X-Attachment-Id", $contentId);

                // add the attachment to the mail
                $swiftMail->embed($attachment);
            }
        }

    /* ... etc ... */

In the template I'm setting the source to the content ID like this:

<img src="cid:<logo>">
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程