Magento Transactional Email Codes - Custom Emails

If you need to send some custom emails as part of a custom Magento module development project, you will stumble into the Magento email template system and its confusing mixture of XML requirements.

Rather than go into too much detail here are some pointers about how to achieve what you want to do.

  1. You need to set up your admin options in your system.xml file.

I’m not going to go into the details on how to set up custom admin configuration, for that try here.

Lets assume you have a custom module under the xml path:


that section should look something like this:

<template translate="label">
	<label>Custom Email Template</label>

You need to set your default value in your config.xml file (inside the root config tag)

 <!-- DEFAULTS For Admin System Configuration //-->

Now you also need to define your email template, which goes inside the config/global/ node

       <!-- EMAIL TEMPLATE //-->
                <custom_module_email_template translate="label" module="appliedsb">
                    <label>Custom Template</label>

And then you need to make sure you put the email template inside the locale folder, en_us (or other locales as needed).

Now you need to clear cache and I recommend resaving the custom configuration group in the admin and double check that your Custom Template label is appearing properly in the email templates dropdown for your module.

And that should be it, your module now has a custom email template that has a locale file and is also over rideable with Magento’s own transactional emails system - sweet!

If you get the exception Invalid transactional email code: then double check that all your xml nodes match up and that the locale file is in the correct place, clear your cache, resave the admin config and try again. This bug can be tricky to track down but if you respect the above xml and file layout it should all work.

Tags: developmentmagentocustommoduleemailtransactionalinvalidcode