0

In My account after login, the customer can change the registered email id.I want to send a confirmation mail to the customer whenever the email id is changed. Please let me know how I can achieve it. I am using Magento 1.9.2.

1 Answer 1

0

For check email id has changed you have to create observer and check two events namely customer_save_before and customer_save_after and get email in both the observer if found change you can send email.

create a module for example Smashing_Meta


create Smashing_Meta.xml and put it on app/etc/modules

<?xml version="1.0"?>
<config>
    <modules>
        <Smashing_Meta>
            <active>true</active>
            <codePool>community</codePool>
        </Smashing_Meta>
    </modules>
</config> 

create config.xml inside app\code\community\Smashing\Meta\etc

<?xml version="1.0"?>
<config>
<modules>
    <Smashing_Meta>
        <version>0.0.1</version>
    </Smashing_Meta>
</modules>
<global>
    <models>
        <smashing_meta>
            <class>Smashing_Meta_Model</class>
        </smashing_meta>
    </models>
</global>
<global>
    <events>
        <customer_save_after><!-- observe the event -->
            <observers>
                <smashing_meta>
                    <class>smashing_meta/observer</class>
                    <method>autoMailAfter</method>
                </smashing_meta>
            </observers>
        </customer_save_after>
    </events>
    <events>
        <customer_save_before>
            <observers>
                <smashing_meta>
                    <class>smashing_meta/observer</class>
                    <method>autoMailBefore</method>
                </smashing_meta>
            </observers>
        </customer_save_before>
    </events>
</global>

create Observer.php inside app\code\community\Smashing\Meta\Model

<?php 

class Smashing_Meta_Model_Observer {   


public function autoMailAfter($observer) {
    $customer = $observer->getEvent()->getCustomer();
    $emailnew = $customer->getEmail();

    if(!$emailold==$emailnew){
    $this->writeMsg($email1);

}

} 
public function autoMailBefore($observer) {
    if(Mage::getSingleton('customer/session')->isLoggedIn()){            
        $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
        $customer = Mage::getModel('customer/customer')->load($customerId);
        $emailold = $customer->getEmail();
    }

} 

public function writeMsg($emailold) {

    //put code for send mail

}

} 
6
  • Thank you so much for your code. I have a still a problem. In my account when i add a invalid email id, then also it is saving the id. If the invalid email id is added we cannot send an email confirmation mail. Please help me on how i can solve this.........
    – madhan
    Oct 18, 2016 at 9:22
  • Hi Pavan, Can i get any solution.when i add a invalid email id, then also it is saving the id. If the invalid email id is added we cannot send an email confirmation mail. Please help me on how i can solve this
    – madhan
    Oct 24, 2016 at 6:13
  • Yes i checked but magento defaults check for email validation .when i enter invalid email it gives me error.
    – Pawan
    Oct 24, 2016 at 8:42
  • Hi Pawan, My problem is not related to email validation. Suppose if my email id is "[email protected]". If i have added a email id as "[email protected]"(spelling change) then in this case the submitted email id will be saved but an confirmation email wont be sent to the email id. I hope you understood my problem...
    – madhan
    Oct 24, 2016 at 12:40
  • i got your point but you should send email to email that is used to registered first time.second thing i dont know how to validate this thing. because how you know that email exist or not .or you can enable Require Emails Confirmation first time a user registered. thanks
    – Pawan
    Oct 24, 2016 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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