开发者

swiftmailer :: send virtual file?

开发者 https://www.devze.com 2023-01-29 03:52 出处:网络
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.

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

精彩评论

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