Question

I am sending an email to an api that 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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top