电子邮件模板“ custom_mail_template”未定义


10

我正在尝试从自定义模块发送邮件。为此,我创建了system.xml文件,但是返回错误。

错误:

电子邮件模板'custom_mail_template'未定义。

我的代码是:

 <?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>

任何建议将不胜感激。

Answers:


19

您需要email_templates.xmletc文件夹中创建包含以下内容的文件:

<?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>

使用声明模板的文件custom_mail_template在“配置”中具有要使用的模板文件路径的ID 。

之后,您yourfile.html在路径中创建模板电子邮件文件Vendor/YourModule/view/frontend/email/yourfile.html

希望对您有帮助。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.