How can I write an observer that sends email which tracks an eav_attribute yes or no value?

The email get's sent, if value is set to yes.

I already created the attribute and the email template.

I only need help with the observer that sends email if the attribute is set to yes on the admin page for a particular user.


  • You want to send an email after the value of the attribute is set to "Yes", is that a customer attribute or product, category? Dec 29, 2020 at 15:27

1 Answer 1


If you want to send an email on data change of that attribute you can build an observer on the customer_save_after Event, were you want to check the old value and the newest one of the customer and if that changed from NO to YES since this will be triggered every time you'll save the customer.



Your observer with the send function inside:

function send($observer){

        $customer = $observer->getEvent()->getCustomer();

        $old = $customer->getOrigData('custom_attribute');
        $new = $customer->getData('custom_attribute');
        if($old == 0 && $new == 1){
    $emailTemplate = Mage::getModel('core/email_template');
    $emailTemplateVariables = array();
    $emailTemplateVariables['name'] = $customer->getName();
    $emailTemplateVariables['email'] = $customer->getEmail();
    $senderName = Mage::getStoreConfig('trans_email/ident_general/name');
    $senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
    $emailTemplate->send($senderEmail, $senderName, $emailTemplateVariables);
            // Do your stuff and call the email function

Not sure about the part of the email send, but this should do the trick

Your Answer

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

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