如何使用swiftmailer在电子邮件中添加图像?

问题描述 投票:0回答:1

我正在尝试在电子邮件中添加图片。我使用Symfony 4和SwiftMailer。我阅读了文档,论坛,但无法正常工作。所以我尝试了:

 $message = (new \Swift_Message('Title of the email'))
                        ->setFrom('[email protected]')
                        ->setTo($data['email']);

                    $headers = $message->getHeaders();

                    $attachment = \Swift_Attachment::fromPath('assets/img/logo.png');

                    $headers = $attachment->getHeaders();
 $message->setBody(
                        $this->renderView(
                            'resetemail.html.twig',
                            [ 'resetPassword' => $resetPassword], $headers
                        ),
                        'text/html'
                    );
$mailer->send($message);
                    return $this->redirectToRoute("requestMail");

对于树枝,我做了:

<img id="customHeaderImage" align="top" label="Image" src="headers" alt="the title of the logo" class="w640" border="0" style="display: inline">

我还尝试用以下方式替换标题的部分:$ img = $ message-> embed(Swift_Image :: fromPath('assets / img / logo.png'));

但是我只有:enter image description here

如果您有解决方案,我很乐意阅读。

谢谢。

symfony4 swiftmailer
1个回答
0
投票

您可以尝试$ message-> embed(Swift_Image :: fromPath('/ assets / img / logo.png'))

© www.soinside.com 2019 - 2024. All rights reserved.