【问题标题】:Sending an attach document via swiftmailer通过 swiftmailer 发送附件文档
【发布时间】:2016-12-01 19:37:28
【问题描述】:

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

首先我使用 snappyBundle 为 pdf 创建文件 && 使用 liugioBundle 的 xsl 文件。

之后我需要使用 swiftmailer 将其作为附件发送到电子邮件中。

有什么建议吗?

【问题讨论】:

    标签: symfony pdf attachment xls swiftmailer


    【解决方案1】:

    你可以在你的 Switft_Mailer 对象上使用 ->attach() 方法

    http://swiftmailer.org/docs/messages.html

    $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'));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多