How to change the new account email template without using the transactional emails configuration? And why?

Account creation emails are not part of themes so there is no an easy way to override their templates using the hierarchy file search of Magento.

Account email template are store inside the /app/locale/[language]/template/email and, for example, the new account email is the file “account_new.html”.

From the administration panel you can define a new template starting from that one, editing it with a visual editor and setting on system configuration to use that new created template. But with many installation it may be better to directly upload a custom template, of course without override the Magento one (to maintain the installation be upgrade safe).

That template is used by Cutomer module (/app/code/core/Mage/Customer) and referenced from its configuration file: Customer/etc/config.xml. Here the snippet of that configuration:

<customer_create_account_email_template translate="label" module="customer">
<label>New account</label>
<file>account_new.html</file>
<type>html</type>
</customer_create_account_email_template>

Since the template is referenced in a configuration it should be possible so change that configuration in a safe way to force the Customer module to use a different template. On the net you’ll find many solution, for example to create a new module based on Customer.

Too much work for a configuration change, in my opinion.

My preferred way is to override that configuration adding a piece of XML inside the /app/etc/local.xml which you should have after the first installation with your database credentials. The snippet to add is:

<config>
    <global>
        ...
        <template>
            <email>
                <customer_create_account_email_template translate="label" module="customer">
                    <label>New account</label>
                    <file>account_new2.html</file>
                    <type>html</type>
                </customer_create_account_email_template>
            </email>
        </template>  
        ...
    </global>  
    ...
</config>

As you can see the new template is named “account_new2.html” and is must be created inside the /app/locale/[language]/template/email (eventually one copy for each language).

Magento seems not programmed with a way to override the email templates (probably because they are configurable on administration side), but for developers can be very useful to have this way to set a different default email template to protect them self from customer messun up them on administration panels.

Tech notes

The method that send new account email is sendNewAccountEmail() inside the Customer/Customer.php.

The template loader is inside the Core/Model/Email/Template.php and another piece of interesting code is the method getTemplateFile() in Core/Translator.php.

 

Similar Posts

3 Comments

  1. Hi! Thanks for the tutorial and good explanations. i have a question regarding email templates. Do you ever tried to set up a different new account template for each customer group? I have in my site a register form from which the registered customers will go in a specific group. I want that the email which is sent for new account to be different than the default one.
    Thanks,

Leave a Reply