Create custom e-mail template in magento


I hope you are aware with the system.xml file in magento so we will not go deep in to it.just add below code to your system.xml file to add select box for choose our custom template.


<email_template translate="label">
<label>Email Template (Sender Notification)</label>
<frontend_type>select
<source_model>adminhtml/system_config_source_email_template
<sort_order>30
<show_in_default>1
<show_in_website>1
<show_in_store>1

The next step is to add an html-template of the letter. /app/locale/en_US/template/email/contact_sender_notification.html

<!--@subject My Email Subject Subject @-->
<!--@vars {"store url=\"\"":"Store Url", "var logo_url":"Email Logo Image Url", "var logo_alt":"Email Logo Image Alt", "htmlescape var=$data.name" : "Email sender contact form" } @-->
<!--@styles body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; } @-->

<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding:20px 0 20px 0">
            <!-- [ header starts here] -->
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
                        <a href="{{store url=""}}" style="color:#1E7EC8;"><img src="{{var logo_url}}" alt="{{var logo_alt}}" border="0"/></a></td>
</tr>
<!-- [ middle starts here] -->
<tr>
<td valign="top">
<h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">Dear {{htmlescape var=$data.name}},</h1>
Some text</td>
</tr>
<tr>
<td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;">
<center>

Thank you again, <strong>{{var store.getFrontendName()}}</strong>

</center></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
IMPORTANT NOTE :: On the above section you have notice commented code it is not actually commented.

But it use internally in magento to setup subject and var.
If you forgot to define subject it will send mail and raise exceptions in log file.

After adding the code (see above) we will declare the template in the configuration file and will set the template as default in Email Template (Sender Notification) app/code/local/namespace/module/etc/config.xml

<config>
    …
     <global>
         ...
        <template>
            <email>
               <contacts_sender_notification_email_template translate="label" module="{justmodulenameonly}">
                   <label>Contact Sender Notification</label>
                   <file>contact_sender_notification.html</file>
                   <type>html</type>
               </contacts_sender_notification_email_template>
            </email>
        </template>
        ...
    </global>
     ...
    <default>
        <contacts>
            <sender_notification>
                <email_template>contacts_sender_notification_email_template</email_template>
            </sender_notification>
        </contacts>
    </default>
...
</config>

IMPORTANT NOTE :: in the above config.xml file. “contacts_sender_notification_email_template” is the combination of your{section_group_field} of your system.xml file(Please take care of this otherwise it will not reflect on your configuration).

Now you can send mail using this template.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s