How to Install Custom Transactional Email for your Magento website?

If you are owner of an online store, you should know about custom transactional email. It brings multiple benefits such as improving customer confidence, decreasing burdens on other customer service channels, better branding opportunities, being a referral channel, increasing revenue, increasing awareness about customers. With huge benefits like that, there is no reason to ignore installing custom transactional email for your website.

Below, we cover all steps to install it in Magento which you can customize using Ad transactional email section in Magento.

You just need to do forwards following steps seriously.

Step 1:

Create a new module under your local folder, in this case under /app/local/Scommerce/CustomEmail.

Step 2:

Register the module in etc/modules directory and in Scommerce_All.xml or Scommerce_CustomEmail.xml by using code below:

<Scommerce_CustomEmail>
    <active>true</active>
    <codePool>local</codePool>
</Scommerce_CustomEmail>

Step3:

Build config.xml under etc directory of your module /app/local/Scommerce/CustomEmail/etc/config.xml by using the code below:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Scommerce_CustomEmail>
            <version>0.0.1</version>
        </Scommerce_CustomEmail>
    </modules>
    <global>
       <template>
            <email>
                <scommerce_customemail_custom_email_template translate='label' module='customemail'>
                    <label>Custom Email</label>
                    <file>custom_email.html</file>
                    <type>html</type>
                </scommerce_customemail_custom_email>
            </email>
        </template>
    </global>
</config>

With above declaration, Magento knows that you have system configuration in scommerce_customemail→ custom→ email_template xpath. It will appear in system.xml. You must ensure that this xpath matches with system.xml otherwise it is not going to work. This is an important configuration so you have to be careful.

Step 4:

Build system.xml under your module etc directory /app/local/Scommerce/CustomEmail/etc/system.xml by using code below:

<?xml version="1.0"?>
<config>
    <tabs>
        <scommerce translate="label" module="customemail">
            <label>Scommerce Configuration</label>
            <sort_order>100</sort_order>
        </scommerce>
    </tabs>
    <sections>
        <scommerce_customemail translate="label">
            <label>Custom Email</label>
            <tab>scommerce</tab>
            <frontend_type>text</frontend_type>
            <sort_order>100</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>     
                <custom translate="label">
                    <label>Custom</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>100</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <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>10</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>
                        <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>20</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </template_email_modified>
                    </fields>
                </custom>
            </groups>
        </scommerce_customemail>
    </sections>
</config>

Step 5:

Send transactional email and use your Model or Controller class by typing code below:

<?php
       /**
         * Sending email to customer
         *
         * @param type $name
         * @param type $email
         * @return boolean
         */
        private function sendEmail()
        {
            $storeId    = Mage::app()->getStore()->getStoreId();
            $emailId    = $this->helper->getConfigData('sender_email_identity');
            $emailFrom  = $this->helper->getConfigData('email_template');
            $email_address = 'toemailadddress@gmail.com'
             
            /* Sender Name */
            $fromName =Mage::getStoreConfig('trans_email/ident_'.$emailFrom.'/name');
 
            /* Sender Email */
            $fromEmail = Mage::getStoreConfig('trans_email/ident_'.$emailFrom.'/email');
                        
            try{
                    $translate = Mage::getSingleton('core/translate');
                     
                    /* @var $translate Mage_Core_Model_Translate */
                    $translate->setTranslateInline(false);
 
                    $emailTemplate = Mage::getModel('core/email_template');
                     
                    /* @var $emailTemplate Mage_Core_Model_Email_Template */
                    $emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $storeId));
                     
                    $emailTemplate->sendTransactional(  $emailId,
                                                        array('email' => $fromEmail, 'name' => $fromName),
                                                        $email_address,
                                                        null,
                                                        array('custom_var1' => 'Custom Variable Value 1', 'custom_var2' => 'Custom Variable Value 2')
                                                    );
 
                    $translate->setTranslateInline(true);
            }
            catch (Exception $e){
                    return false;
            }          
            return true;
        }

Step 6:

Create custom_email.html to inform in config.xml under /app/local/en_US/template/email/custom_email.html by using code below:

<style type="text/css">
    body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
   .orange { color:#DB7200; }
</style>
 
<div style="font:11px/1.35em Verdana, Arial, Helvetica, sans-serif;">
 
    <table cellspacing="0" cellpadding="0" border="0" width="650">
        <tr>
            <td valign="top">
                <p>
                    <strong>Hello <span class="orange">{{var custom_var1}}</span></strong>,<br/><br/>
                    {{var custom_var2}}
                  </b>
                </p>
                <p>
                  Thank you again for purchasing from My Website.
                </p>
                Kind Regards</br></br>
             
            </td>
        </tr>
    </table>
</div>

Finish all steps above means that you are successful in installing custom transactional email in Magento website. Contact us if you have any questions. Or else visit Magento tutorial to consult others.