开发者

swiftmailer :: send virtual file?

I am sending an email to an api that开发者_Go百科 gets its content from an attached file.

I do not want to actually create the file (its like one line of text) and then attach it and send it.

Is it possible to create a filestream and send that through swiftmailer?


Turns out Swiftmailer supports Dynamic Attachments.

The basic idea is:

//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);

Hope this helps someone out there.


I have always had to create the file and then attach it with SwiftMailer.

Though you can unlink() the file as soon as the email has been sent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜