Magento 1

Emails in Magento: A Guide

Emails in Magento can be incredibly tricky. Firstly, you’ll want to define a field in system config for the template itself; the location of this field dictates the structure of the default node it uses to retrieve available templates and children.

        <rayware translate="label" module="rayware">
        <rayware translate="label" module="rayware">
                <reg_email translate="label">
                    <label>Registration Email</label>
                        <email_template translate="label description" module="rayware">
                            <label>Email Template</label>
                            <description>The template used to send new user reqistrations to rayware</description>

The class adminhtml/system_config_source_email_template finds its default using its own node structure by converting its slashes to underscores, and then looking in global/defaults/template/email so it’ll look here:

            <rayware_reg_email_email_template translate="label" module="rayware">
                <label>[Rayware] New Customer Email</label>

So: The location of system config setting for the email template dictates where the actual template should live in global/template/email node.


The structure of the system config node above dictates where the default should be located. In this instance, it’ll be the following – and the contents of the node should refer to the node name in global/template/email/ above


Sending Emails

$mailTemplate = Mage::getModel('core/email_template');
	'area' => 'frontend',
	 'store' => Mage::app()->getStore()->getId()

$mailTemplate->sendTransactional($templateId, $senderName, $toEmail, $toName, $bind = array(), $storeId = null);
  • Templateid can either be a string or a number, if it’s retrieved from the config then it’ll be worked out automatically if the value has been saved. For the current example, Mage::getStoreConfig(‘rayware/reg_email/email_template’); would be used
  • Sender Name – this refers to one of the transactional sender names in the admin. The name entered here is used to look up a config path in Mage::getStoreConfig(‘trans_email/ident_’ . $sender . ‘/name’);
  • toEmail – the email to send to, this can be an array of email addresses
  • toName – the name of the person to send the email to – this can be an array of names
    bind – array of variables which can be used in the email (See directives)


Define what variables are available in the email using comments at the top of each email file. The subject is also defined in this way.

logo_url and logo_alt are populated from the admin area. The purpose of variables is to allow easy inserting of them from the admin area – this would appear to be their only purpose. The part after the colon is the part which will be shown in the dropdown in the admin (the user friendly name).

<[email protected] Your Quote #{{htmlescape var=$quotation.quote_id}}@-->
<[email protected]
{"store url=\"\"":"Store Url",
"var logo_url":"Email Logo Image Url",
"var logo_alt":"Email Logo Image Alt"}

Email template files live in app/locale/<<country_CODE>>/template/email/ where country code is the code of the country set in the admin area.
The templates can also be placed in en_US, which is the last level of fallback.

Email templates in the database live in the core_email_template table.

Any of the vars can be placed in the subject field using the above, E.g:

<[email protected] {{var title}}@-->



Used to pull out any variables which are passed in to the template via the ‘bind’ parameter. Methods can also be called on passed in variables on the email objects:

{{var subscriber.getConfirmationLink()}}
$bind = array(
    'passedInVariable'  => array(
        'horse' => ‘Moose’


Creates the block, and sets the parameters on them (or calls the methods). If type is not set as a parameter

{{block type=‘cms/block’ customVar=‘1’ methodToCall=‘test’}} 


{{protocol}} -current protocol http or https
{{protocol url=""}} domain URL with current protocol
{{protocol http="http://url" https="https://url"} - also allow additional parameter "store"


{{config path="path/to/config}}


{{customvar code="custom_var_code"}}


{{inlinecss file="path/to/file.css"}}


Loads the layout handle specified and sets all variables on each of the blocks in the layout handle. Methods can also be called on the blocks in the layout handle using this method, if they exist. “area” can also be set as a parameter but will default to the current area if not. Most likely this will be ‘frontend’.

{{layout handle="my_custom_layout_handle_to_be_used" variable="test" method="moose"}}


Embeds the url to a skin asset.

{{skin url="path/to/asset.ext"}}


Embeds a media url.

{{media url="path/to/media/asset.ext"}}


Get the URL for the store. If the url doesn’t end in a suffix, then ‘URL’ can be used, otherwise, direct_url should be used instead. Parameters can also be passed into the url using the syntax _query_paramName=”paramValue”.

{{store url="contacts"}} //
{{store direct_url="html_file.html"}} //
{{store direct_url="goosey.html" _query_param="horseparam"}} // http://dave.magento-test-2.iweb/goosey.html?param=horseparam


Escapes the variable which is passed in from the bind array. certain tags can also be ignored using the allowed_tags parameter

{{htmlescape var="<b>Moose</b>" allowed_tags="b"}} // This would output the moose and keep the bold tags unescaped. See the var directive above for referencing bind params in the same way for htmlescape.