Email template 'custom_mail_template' is not defined
-
13-12-2019 - |
Question
I'm trying to send mail from my custom module. For this I have created system.xml
file, but it's returning error.
Error:
Email template 'custom_mail_template' is not defined.
my code is:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="custom" translate="label" sortOrder="1">
<label>custom mail</label>
</tab>
<section id="custom" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>custom mail</label>
<tab>custom</tab>
<resource>Learning_Custom::config_custom</resource>
<group id="mail" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Custom</label>
<field id="active" translate="label" type="select" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="template" translate="label comment" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Email Template</label>
<comment>Email template chosen based on theme fallback when "Default" option is selected.</comment>
<source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
</field>
</group>
</section>
</system>
</config>
Any suggestions will appreciate.
Solution
You need create file email_templates.xml
in etc
folder with content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="custom_mail_template" label=" Your Custom Label" file="yourfile.html" type="html" module="Vendor_YourModule" area="frontend"/>
</config>
This file using declare template have id custom_mail_template
in Configuration with path of template file you want use.
After, you create template email file yourfile.html
in path Vendor/YourModule/view/frontend/email/yourfile.html
I hope it help for you.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange