Kimigx
Kimigx

Reputation: 91

Sending Base64 PDF as email in symfony 2.8>

I have a PDF generated by jsPDF as a blob/base64 string, and I want to sent it to recipients through swiftmail without having to decode the string, create a PDF file and finnally attach it to the Mail.

My question is, Is their a way of attaching Bas64 to swiftmail and if it is possible will the recipient be able to see the file as a PDf using PDF viewers.

Upvotes: 1

Views: 2326

Answers (2)

Gollm
Gollm

Reputation: 130

You have to decode the string

$mail->attach(new \Swift_Attachment(base64_decode($pdfBase64String), 'Pdf.pdf', 'application/pdf'));

Upvotes: 1

Mawcel
Mawcel

Reputation: 1995

In order to attach a file to a SwiftMail you need to provide the content to Swift_Attachment::setBody() and it can NOT be base_64 (i already tried with images) or create the actual file in the filesystem and use Swift_Attachment::fromPath() so you will HAVE to decode you pdf anyways.

SwiftMailer doc: http://swiftmailer.org/docs/messages.html#attaching-existing-files

Upvotes: 2

Related Questions