Kri*_*dke 7 php email swiftmailer symfony
我在symfony2中使用swiftmailer发送电子邮件,但我想将指定的PDF文件添加为电子邮件的文件附件.我该怎么办?
这是我目前的代码:
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody(
$this->renderView(
'HelloBundle:Hello:email.txt.twig',
array('name' => $name)
)
)
;
$this->get('mailer')->send($message);
Run Code Online (Sandbox Code Playgroud)
小智 10
您可以使用swift邮件程序将文档附加到电子邮件中.
从symfony doc:
$message = Swift_Message::newInstance()
->setFrom('from@example.com')
->setTo('to@example.com')
->setSubject('Subject')
->setBody('Body')
->attach(Swift_Attachment::fromPath('/path/to/a/file.zip'))
;
$this->getMailer()->send($message);
Run Code Online (Sandbox Code Playgroud)
小智 6
如果要从缓冲区上传文件,可以执行以下操作:
$attach=getPdfFunction(); //binary
Swift_Attachment::newInstance($attach, 'document.pdf','application/pdf');
Run Code Online (Sandbox Code Playgroud)
您可以使用以下行添加附件:
$message->attach(\Swift_Attachment::fromPath($attach));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11983 次 |
| 最近记录: |