Attaching PDF file to email on Magento 2


In Magento 2, The lib/internal/Magento/Framework/Mail/Template/TransportBuilder Class takes responsibility for preparing and sending email, but it’s still lacking a method for attaching PDF files.

However, since the TransportBuilder Class uses Message class, which inherits from \Zend_Mail, we are now able to add attachments programmatically.

Here is how we do it.

Step 1: Create TransportBuilder Class

Step 2: Create sample Email Sending on Controller

That’s all for the coding part.

Try to run the controller and check the result on the receiver’s email.

You will see a PDF file in the sent email like in the image below.

Hope this topic is helpful for you. Don’t mind leaving your questions here if you have any problems.



Relevant Entries
Magento 2 Cache Guide20170407044105
How To Configure Github API In Magento 220170918200005
How to Configure Vkontakte API in Magento 220171003200043