swiftmailer :: send virtual file?
-
10-10-2019 - |
سؤال
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?
المحلول
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.
لا تنتمي إلى StackOverflow