Symfony 通过swiftmailer发送附加文档

Symfony 通过swiftmailer发送附加文档,symfony,pdf,attachment,xls,swiftmailer,Symfony,Pdf,Attachment,Xls,Swiftmailer,我正在尝试将文件附加到电子邮件 首先,我使用snappyBundle for pdf创建文件&使用liugioBundle创建xsl文件 之后,我需要发送它作为附件文件在电子邮件中使用swiftmailer 有什么建议吗?您可以在Switft\u Mailer对象上使用->attach()方法 $email = \Swift_Message::newInstance() ->setSubject('Subject') ->setFrom('me@domain.com

我正在尝试将文件附加到电子邮件

首先,我使用snappyBundle for pdf创建文件&使用liugioBundle创建xsl文件

之后,我需要发送它作为附件文件在电子邮件中使用swiftmailer


有什么建议吗?

您可以在Switft\u Mailer对象上使用->attach()方法

$email = \Swift_Message::newInstance()
    ->setSubject('Subject')
    ->setFrom('me@domain.com')
    ->setTo($recipients)
    ->setBody(
        $this->renderView(
            'Emails/niceEmail.html.twig',
            compact('foo', 'bar', 'message')
        ),
        'text/html'
    )
    ->attach(Swift_Attachment::fromPath('my-document.pdf'));