How to Add Attachments with Email in Magento 2.3.x

The Magento 2.3.x versions use the Zend Framework 2. The implementation of various functionalities is different from the previous versions as it refuses to apply Zend Framework 1 (ZF1).

One such function is to send Emails with attachments. With the function createAttachment() in the previous Magento 2 versions, it was easy to add attachments in Emails.

However, if you are using the upgraded versions (I’m sure you’re enough concerned with the security and thus using the latest Magento 2.3.2), use the below code to add attachments with Email in Magento 2.3.x.

You may refer the below manuals for more knowledge about ZF2 components:

Method to Add Attachments with Email in Magento 2.3.x:

  1. Add following code in di.xmlNote:If you want to attach the file in frontend – vendor\module\etc\frontend\di.xml
    If you want to attach the file in backend– vendor\module\etc\adminhtml\di.xml
    If you want to attach the file in both frontend and backend – vendor\module\etc\di.xml
  2. Create Message.php file at Vendor\Module\Mail\Message.php
  3. Create MessageFactory.php file at Vendor\Module\Mail\MessageFactory.php
  4. Create TransportBuilder.php file at Vendor\Module\Model\Mail\Template\TransportBuilder.php
  5. Use TransportBuilder object in the file where you want to add an attachment in the Email.
    For example Vendor/Module/Helper/Data.php

Method to Add Attachments with Email in Magento 2.3.3:

  1. Create di.xml file at app/code/vendor/module/etc/

  2. Create TransportBuilder.php at app/code/vendor/module/model/mail/template/


Add attachment in email like :

That’s all you need to do for implementing Emails with attachments in Magento 2.3.x

Please use the Comments section below to mention any doubts on the topic. I’d be glad to help you out.

You may share the above solution with the Magento community via social media.



(based on 25 Reviews)
How to Add Attachments with Email in Magento 2.3.xAuthor Magento Badge

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.


Leave a Reply

Your email address will not be published. Required fields are marked *