Magento 2.3+ – Attach a PDF on an email programmatically

Adding a custom made PDF inside an email would be something that you might need to develop, which is not standard contemplated by the core TransportBuilder Magento library, but don’t worry, this is not the end of the world, in this post am i going to show you how to proceed and get with an accurate solution.

0- You will need to create the PDF file. Follow this post to do so: Create PDF

1- Create your custom email template




2- Create your TransportBuilder class:




3- Attach the PDF and send the EMail.



Remember to redeploy the static content, clean cache, and compile your files. Afterwards you will be able to test.