Pages

Tuesday, 8 July 2014

Customer Registration Email Notifications in Magento

Customer registration e-mail notification helps you to get the e-mail notification when new customer visit & register on your website. It makes you up-to-date about your new customer & helps to increase your business sales.

 Recently I have performed a task for sending an e-mail when new registered customers only, So that they can confirm.

Follow Below Steps to achieve this, I am assuming you are aware with the custom module development in magento

Step 1: Add below code into your etc/config.xml under global node

<global>                                                                                         
    <models>                                                                                     
        <easylife_notifyusers>                                                                   
            <class>Easylife_Notifyusers_Model</class>                                            
        </easylife_notifyusers>                                                                  
    </models>                                                                                    
    <template>                                                                                   
        <email>                                                                                  
            <notify_new_customer module="Easylife/Notifyusers">                                  
                <label>Template to notify administrator that new customer is registered</label>  
                <file>notify_new_customer.html</file>                                            
                <type>html</type>                                                                
            </notify_new_customer>                                                               
        </email>                                                                                 
    </template>                                                                                  
</global>


 Step 2:  After global tag, add below code to handle Observer/Event : because in my case I am sending email user Observer. Add below code into your etc/config.xml.


<frontend>                                                                     
    <events>                                                                  
        <customer_save_after>                                                 
            <observers>                                                       
                <easylife_notifyusers_observers>                              
                    <type>model</type>                                        
                    <class>Easylife_Notifyusers_Model_Observer</class>        
                    <method>customerRegisterSuccess</method>                  
                </easylife_notifyusers_observers>                             
            </observers>                                                      
        </customer_save_after>                                                
    </events>                                                                 
    </frontend> 
       

                                                      
Step 3: Add HTML file into your app/locale/en_US/template/email folder




Congratulations, You have successfully registered from Magento Site:<br />
Name             : {{var username}}<br />
Email            : {{var customer_email}}<br />
Your Password is : {{var password}}<br/>
...<br />


All variables written here under parenthesis would get set in step 4 ..see the function below.

Step 4: Add this function into your observer file under Model/Observer.php


<?php

class Easylife_Notifyusers_Model_Observer
{
    public function customerRegisterSuccess(Varien_Event_Observer $observer)
    {
        if (Mage::registry('my_observer_has_run')) {
            return $this;
        }

        Mage::register('my_observer_has_run', true);

        if (!$observer->getCustomer()->getOrigData()) {
            //customer is new, otherwise it's an edit


            $emailTemplate  = Mage::getModel('core/email_template')
                ->loadDefault('notify_new_customer');
            $emailTemplate
                ->setSenderName(Mage::getStoreConfig('trans_email/ident_support/name'))
                ->setSenderEmail(Mage::getStoreConfig('trans_email/ident_support/email'))
                ->setTemplateSubject('New Customer Registered');

            $data = $observer->getCustomer()->getData();

            //Mage::log((array)$data);

            $emailTemplateVariables['username']= $data['firstname'].' '.$data['lastname'];
            $emailTemplateVariables['customer_email']   = $data['email'];
            $emailTemplateVariables['password']   = $data['password'];

            $result = $emailTemplate->send(Mage::getStoreConfig('trans_email/ident_general/email'),Mage::getStoreConfig('trans_email/ident_general/name'), $emailTemplateVariables);
        }
    }
}


 Step 5: After adding this code we need to Configure the E-Mail in General Contact.

1) Go to Admin->System->Configuration.
2) Select the tab General->Store Email Addresses->General Contact.
3) Here is the sender email option which is owner email id, the email id you set here will receive the email whenever the new customer register on your website.

 Step 6: Go to your magento site and registred the test account you will recieve thd e-mail notification.

Cheers!!!..

If you have any queries leave a comment.   

No comments:

Post a Comment