Support & Downloads

Quisque actraqum nunc no dolor sit ametaugue dolor. Lorem ipsum dolor sit amet, consyect etur adipiscing elit.

s f

Contact Info
198 West 21th Street, Suite 721
New York, NY 10010
[email protected]
+88 (0) 101 0000 000
phtml file

How to Use phtml File in Email Template in Magento 2

Magento 2 store owners send emails to customers for not only marketing purposes but also for sending the order, shipping, and invoice details.

For branding purposes, the merchants use custom email templates over the default one. When a customer receives emails having the store name and logo with a well-organized email template design, it makes a great impression.

To check the email template design while creating, Magento 2 offers the preview option. That shows how the email template design will look in the frontend. However, the process is complicated and time-consuming as well.

Here are the steps that you have to follow for checking the output of the design of the email template from the admin panel:

  1. Login to Magento 2 admin panel
  2. Login to Magento 2 admin panel
  3. Visit Marketing > Communications > Email Templates 
  4. Click on Add New Template
  5. Select and click on Load Template
  • Now, click on Preview Template to see the changes that you have made.

However, the programmatic method to use phtml file in Email template in Magento 2 can be a better option that eliminates the above steps and removes the admin’s dependency.

Steps to Use phtml File in Email Template in Magento 2

Create app/code/Vendor/Extension/registration.php

Create app/code/Vendor/Extension/etc/module.xml

Create app/code/Vendor/Extension/etc/frontend/routes.xml

Create app/code/Vendor/Extension/Controller/Index/Index.php

Create app/code/Vendor/Extension/view/frontend/layout/extension_index_index.xml

Create app/code/Vendor/Extension/Block/Extension.php

Create app/code/Vendor/Extension/view/frontend/templates/template_file.phtml

Create app/code/Vendor/Extension/view/frontend/email/email_template.html

Create app/code/Vendor/Extension/etc/email_templates.xml

Create app/code/Vendor/Extension/Helper/Data.php

That’s it.

If you have queries regarding this post, feel free to ask in the Comments section below.

I would be happy to help you.

Do consider sharing this article with Magento Community via social media.

Thank you.

Sagar Doshi

CEO / Managing Partner

[email protected]

Post a Comment