My Custom Observer is not sending the email.

public function sendAdminMail(Varien_Event_Observer $observer)
    $customer = $observer->getEvent()->getCustomer();

    $customerName = $customer->getFirstname() . ' ' . $customer->getLastname();

    $emailTemplate = Mage::getModel('core/email_template');
    $template = "customer_registration_email_template";
    $sender = array('name' => 'Customer Registration',
                    'email' => '[email protected]');
    $recipientEmail = Mage::getStoreConfig('contacts/email/recipient_email');
    $recipientName = "Sales";
    $variables = array('customer'=>$customerName);


Here is my config.xml (global node)

            <customer_registration_email_template translate="label" module="adminnotification">
                <label>Customer Registration Admin Notification</label>

To be complete, here is the system.xml too

<label>Customer Registration Admin Notification</label>

An email should be sent to the admin when a new customer registers.

What am I doing wrong here? The template is showing in the list of Transactional mails in the backend and it sends when I use it testwise for new orders for example.

Strange is also, that the content of the template does not load in the backend (transactional mails) when I add a new template and want to load its default content (it just loads and stays blank).

Any help appreciated. Thanks in advance!

1 Answer 1

      public function sendAdminMail(Varien_Event_Observer $observer)
      $customer = $observer->getEvent()->getCustomer();

      $customerName = $customer->getFirstname() . ' ' . $customer->getLastname();

      $emailTemplate = Mage::getModel('core/email_template')->loadDefault('customer_registration_email_template');
      $senderName = 'Customer Registration';
      $senderEmail = '[email protected]';
      $emailTemplateVariables = array();
      $emailTemplateVariables['customer'] = $customerName;
      $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
      $recipientEmail = Mage::getStoreConfig('contacts/email/recipient_email');
      $recipientName = "Sales";
      $mail = Mage::getModel('core/email')

          catch(Exception $error)
              return false;

Try this code. Not sure other things you have done are correct or not. If you are using any mail senders like mandril then the sender email should be in your domain.

  • Thanks but I want to use email templates, so I need a solution with the sendTransactional().
    – Th. Schott
    Nov 28, 2017 at 9:08
  • You can use template in this. Check line no 4 Nov 28, 2017 at 9:27
  • Using this code it sends a mail but the body is empty. Anyway I would prefer using the sendTransactional() as proposed here but I cannot find the problem.
    – Th. Schott
    Nov 28, 2017 at 10:12
  • The problem with the empty body may be due to the way in which you have declared the template in the config.xml. You can use sendTransactional as you said, I am using this script for the custom emails. Nov 28, 2017 at 10:24

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.