2010-12-08 87 views
2

我正在发送一封电子邮件到一个从附件中获取其内容的api。swiftmailer ::发送虚拟文件?

我不想实际创建文件(它像一行文本),然后附加并发送它。

是否可以创建一个文件流并通过swiftmailer发送?

回答

2

变成Swiftmailer supports Dynamic Attachments

的基本思路是:

//Create your content in a variable. 
$content = "Hi there\r\nHow are you"; 

//Create a Swiftmailer attachment 
//specify the data, filename, mimetype 
$attachment = Swift_Attachment::newInstance($content, 'my-file.pdf', 'application/pdf'); 

//attach the file 
$message->attach($attachment); 

希望这有助于有人在那里。

+0

+1很高兴你知道了,我会在未来检查这一点:) – alex 2010-12-08 13:00:25

1

我一直都要创建该文件,然后将其与SwiftMailer附加。

虽然您可以unlink()该文件尽快发送电子邮件。

+0

那么好消息,我找到了答案:http://swiftmailer.org/docs/dynamic-attachments – Hailwood 2010-12-08 09:50:48