Menu Close
    Hire us Request quote Reading list Switch to dark mode
    lockdownWebkulUp

    How to attach Pdf file in Magento 2 Email

    Here we learn, how to send attachment in magento 2 email programmatically. I have attached pdf file here.

    Magento 2 uses the lib/internal/Magento/Framework/Mail/Template/TransportBuilder class to send mail, which doesn’t support attachment yet.

    TransportBuilder class uses the lib/internal/Magento/Framework/Mail/Message.php to prepare the email message.

    Here we can observe that Message class extends \Zend_Mail so we can add attachment functionality in TransportBuilder Class.

    1. create your TransportBuilder class, Webkul/EmailDemo/Model/Mail/TransportBuilder.php

    . . .
    Subscribe Articles

    Just enter your email below to subscribe and receive weekly updates about the most interesting similar articles.

    You need to accept conditions to receive letters.
    You've Subscribed!

    Share article via

    . . .


    2. Here i have created sample Email Sending Helper, Webkul/EmailDemo/Helper/Data.php

    That’s it.

    . . .

    Comments (2)

    Add Your Comment

  • Rajan Soni
    sendMessage is not working
    Uncaught Error: Call to undefined method [NAMESPACE][MODULE]ModelMailTransportBuilder::sendMessage()
  • Gavino Covone
    Hello,
    sending e-mail with an attachment is working properly.

    But the email arrives in spam. How to do to not let it get to spam?

    Thank you.

  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close