Back to Top

Magento2 – Create and Use Custom Email Templates

Updated 16 July 2021

Here will see how to create Email Templates in magento2.

Email Templates in Magento2

First create ’email_templates.xml’ file in folder ‘Webkul/Hello/etc’.

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
	<template id="hello_template" label="Hello World" file="hello.html" type="html" module="Webkul_Hello" area="frontend"/>

Now create email template file ‘hello.html’ in folder ‘Webkul/Hello/view/frontend/email’.

<!--@subject Email Subject @-->
{"store url=\"\"":"Store Url",
"skin url=\"images/logo_email.gif\" _area='frontend'":"Email Logo Image"}
body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
{{template config_path="design/email/header_template"}}
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<td align="center" valign="top" style="padding:20px 0 20px 0">
					<table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
							<td valign="top">
								<h1 style="font-size:22px;font-weight:normal;line-height:22px;margin:0 0 11px 0;">{{trans "Hello"}},</h1>
								<table cellspacing="0" cellpadding="0" border="0" width="650">
											<td colspan="2" valign="top" style="font-size:12px;padding:7px 9px 9px 9px;border:1px solid #EAEAEA;">
												{{var message}}
							<td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA;text-align:center;">
									<p style="font-size:12px;margin:0;">
										<strong>{{trans "Thank you"}}</strong>
	{{template config_path="design/email/footer_template"}}
Email Templates

This is an example of template. you can set your own message body and can send as many as variable as you can.

Now Call this template from where you want to call it.

Searching for an experienced
Magento 2 Company ?
Find out More
$templateOptions = array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->storeManager->getStore()->getId());
$templateVars = array(
					'store' => $this->storeManager->getStore(),
					'customer_name' => 'John Doe',
					'message'	=> 'Hello World!!.'
$from = array('email' => "[email protected]", 'name' => 'Name of Sender');
$to = array('[email protected]');
$transport = $this->_transportBuilder->setTemplateIdentifier('hello_template')

$this->storeManager is instance of ‘Magento\Store\Model\StoreManagerInterface’

$this->_transportBuilder is instance of ‘Magento\Framework\Mail\Template\TransportBuilder’

$this->inlineTranslation is instance of ‘Magento\Framework\Translate\Inline\StateInterface’

. . .

Leave a Comment

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


  • dev Webwavers
  • Cero
  • vishal
  • dishank
  • dishank
  • vishal
    • Rahul
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home