Magento 2 Email Templates

How to Customize Magento 2 Email Templates

Emails are still the number one channel to communicate with your customer in 2020. Magento 2 is sending automated emails to inform the customers. Those emails are also known as transactional emails. It can be confirmation about new order, invoice, newsletter subscription and so on. In total, there are 31 already prepared email templates in Magento 2. Unfortunately, they aren’t perfect and you might need to customize them.

Location, where you can manage Magento 2 email templates:

Marketing > Communications > Email Templates

Step by step guide how to customize email templates

Magento 2 Email templates consist of two parts: html+css and variables. The variables are replaced to real data, when Magento prepares a template for sending. In other words, a variable is just a simple text like {{var customer_email}}, which will be replaced with a receiver email address.

Email template customizations consists of three steps:

  1. Load a default email template
  2. Customize email template
  3. Update configuration

1. Load a default email template

First of all we need to create a new template and load Magento default template which we will customize. If you’re ready, when go to:

Marketing > Communications > Email Templates > Add New Template

Then, choose a template, which you want to customize. In my example, I will use the “New Order” email template. After that click the “Load Template” button.

2. Customize email template

You will need to enter a unique email template name, before starting all customizations. It can be for example “Luma New Order”.

In the form field “Template Content” all the magic will happen. I won’t go very deep in the details about variables, if conditions, css and other things. Magento 2 has written a great article about it on their own documentation.

Unfortunately, Magento 2 hasn’t wysiwyg editor for email templates. If you don’t know or don’t want to edit plain html, I would like to suggest our Magento 2 Email Templates extension. It has a user friendly editor, especially built for Magento 2 Email Templates. But about it a little bit later in this post.

If you have changed what you want in email template content, then click the “Save Template” button and we will be ready for the last step.

3. Update configuration

After we have created an email template, we need to update configuration and replace old template to the new one. In my example, I mentioned, that I will use the “New Order” template. So in my case, I will have to navigate:

Stores > Configuration > Sales > Sales Emails > Order > New Order Confirmation Template 

Magento path is depending on email template. You can always check the right configuration path in Magento 2 documentation.

If you have updated your configuration successfully, before testing, make sure a cache is cleaned. Otherwise, you will receive the same email template as before.

User friendly email template editor for Magento 2

I already mentioned our Magento 2 Email Templates extension above, but I would like to couple more details about it. It’s a really helpful extension and can save tons of time. There are 31 email template in Magento 2 and to modify them all might be challenging. 

This Magento 2 Email Templates extension has a user friendly email template editor. It lets you customize email templates in preview mode. One of the greatest things about it, is that it has a possibility to apply the changes for all templates at once. It saves time. Using this editor, you don’t need to update colors, fonts, button colors, backgrounds, header, footer, etc for each template. Here is a short video about how this extension is working.

Troubleshooting

And the final piece for this article, as always troubleshooting tips. When we’re talking about Magento 2 email templates, two problems are coming to my mind. Those are more often than others.

Email is not sent

If you aren’t receiving emails from the Magento system there might be several reasons:

Reason #1 – cron is not working 

If crontab is not configured properly or wasn’t at all, it can affect all sales email messages. My suggestion is to disable the following options and try to send email again. If a message is sent, then the problem is with a crontab.

Stores > Configuration > Sales > Sales Emails > General Settings > Asynchronous sending 

Reason #2 – An Error in email template

Email messages might not be sent because of some error. You can look for the errors in error logs, under this location in your server.

{MAGENTO_BASE_DIR}/var/log/system.log
{MAGENTO_BASE_DIR}/var/log/exception.log

Reason #3 – Email communication is not working

If you have already checked issues above, then there is a chance that your server isn’t sending emails using PHP mail() function and you don’t have installed any SMTP extension. There are a bunch of SMTP extensions out there, just grab a free. It will do its job.

Email has “Call to a member function on null” error

It’s one of more often problems, caused by misunderstanding how email templates are working in Magento 2. The functionality, which is using template, isn’t passing a variable required by template. As an example, a “New Order” template can’t be used to send abandoned cart email messages. They both have items on email templates, but the way they gets data are different. Make sure all variables are passed by functionality which will use email template.

If I were missing something, let me know in the comments below. I will be more than happy to append this article. That’s all for this post, fellows. Cheers!

Leave a Comment