2

I want to send a confirmation mail to the customer when has customer login. Please let me know how can I achieve it. I am using Magento 1.9.2.

this is my _loginPostRedirect() function code

 protected function _loginPostRedirect()
{
    // send mail after login start here
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $templateId = 2; // USE YOUR OWN TEMPLATE ID
    $senderName = Mage::getStoreConfig('trans_email/ident_support/name');  
    $senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');  
    $sender = array('name' => $senderName,
        'email' => $senderEmail);
    $recepientEmail = $customer->getEmail();
    $recepientName = $customer->getName();
    $store = Mage::app()->getStore()->getId();
    $vars = array('customerName' => $customer->getName()); 
     Mage::getModel('core/email_template')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
// send mail after login end here 
1

You have to override Account controller,

First copy AccountController.php

From

/app/code/code/Mage/Customer/controllers/AccountController.php

To

/app/code/local/Mage/Customer/controllers/AccountController.php

Here you will find method: _loginPostRedirect()

Here you can put confirmation mail code.

1

If you do not want to create a module, you can override Account controller using the following steps:

1) Make a New Email Template from Transactional Emails and note the ID of it.

hello {{var customerName}},
    You are succesfully logged in.
Thank you

2) Copy AccountController.php file From: /app/code/code/Mage/Customer/controllers/AccountController.php

To: /app/code/local/Mage/Customer/controllers/AccountController.php

3) Search for method: _loginPostRedirect() in AccountController.php

and put the below code at the start of this function

$customer = Mage::getSingleton('customer/session')->getCustomer();
$templateId = 8; // USE YOUR OWN TEMPLATE ID
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');  
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');  
$sender = array('name' => $senderName,
            'email' => $senderEmail);
$recepientEmail = $customer->getEmail();
$recepientName = $customer->getName();
$store = Mage::app()->getStore()->getId();
$vars = array('customerName' => $customer->getName()); 
Mage::getModel('core/email_template')
    ->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
  • we have chat on this topic have you deleted can you share that. – Sarvesh Tiwari Mar 30 '17 at 13:45
0

Main idea is to create an Observer for the controller_action_postdispatch_customer_account_loginPost event:

     <controller_action_postdispatch_customer_account_loginPost>
        <observers>
            <module_postdispatch_customer_account_loginpost>
                <class>Namespace_Module_Model_Observer</class>
                <method>postLogin</method>
            </module_postdispatch_customer_account_loginpost>
        </observers>
    </controller_action_postdispatch_customer_account_loginPost>

and check in the postLogin function if the customer is logged in:

if (Mage::helper('customer')->isLoggedIn()) {
   // send mail to customer
}

Your final structure sould be:

app/code/local/<namespace>/<module>/etc/config.xml
app/code/local/<namespace>/<module>/Model/Observer.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.