Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top