我正在尝试在电子邮件中添加图片。我使用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'));
如果您有解决方案,我很乐意阅读。
谢谢。
您可以尝试$ message-> embed(Swift_Image :: fromPath('/ assets / img / logo.png'))