0

I am creating a custom module in Magento which send emails. I've created the email template in the "transactional email templates" section in the backend, and it works.

Now I would like to add the email template in the files of Magento to have a durable solution (currently, if I reset the database configuration, my template will be removed). I can't find a way to load the template.

  1. I've created my template file in app/locale/en_GB/template/email/notification.html
  2. I've tried to declare this template in my config.xml

    <template>
        <email>
            <vendor_report_notification_email_template translate="label" module="namespace_ordersReport">
                <label>Vendor Report Notification Template</label>
                <file>notification.html</file>
                <type>html</type>
            </vendor_report_notification_email_template>
        </email>
    </template>
    

I can't find how to add an email template and how to load it to 1. be able to send an actual email, 2. customize it in the backend if needed through the load template function of the transactional emails.

3
  • Since you have placed your template in en_GB then your store should be en_GB too I guess. Hope you know this already. Jun 24, 2015 at 11:55
  • Yes, my store is configured with en_GB as locale
    – chris
    Jun 24, 2015 at 12:15
  • Did you manage to resolve your issue?
    – Sander Mangel
    Jun 25, 2015 at 10:50

2 Answers 2

1

You will need to add some fields to the system.xml

[...]
<!-- sender -->
<sender_email_identity translate="label">
    <label>Email Sender</label>
    <frontend_type>select</frontend_type>
    <source_model>adminhtml/system_config_source_email_identity</source_model>
    <sort_order>20</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</sender_email_identity>

<!-- template -->
<email_template translate="label">
    <label>Email Template</label>
    <frontend_type>select</frontend_type>
    <source_model>adminhtml/system_config_source_email_template</source_model>
    <sort_order>30</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</email_template>
[...]

And retrieve and set the data where ever you want to send it from

$templateData = new Varien_Object();
$templateData->setData(array(
    'varname' => 'value',
    'varname' => 'value',
));

$translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false);

$mailTemplate = Mage::getModel('core/email_template');
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
    ->sendTransactional(
        Mage::getStoreConfig('path/of/email_template'),
        Mage::getStoreConfig('path/of/sender_email_identity'),
        'recipient@example.com',
        null,
        array('data' => $templateData)
    );

if (!$mailTemplate->getSentSuccess()) {
    throw new Exception();
}

$translate->setTranslateInline(true);
0

You will need to mention it in your system.xml in order to having that functionality.

Check this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.