Sending an admin notification on successful customer registration in Magento involves setting up an event observer and email template. Let’s go through the correct steps to ensure your configuration works as expected.
Understanding the Event Observer
The customer_register_success event is triggered whenever a new customer registers successfully on your Magento store. You need to create a model that observes this event and sends an admin notification email when it occurs.
In your provided config.xml, you have correctly defined the event observer in the frontend section:
<frontend>
<events>
<!-- registration success -->
<customer_register_success>
<observers>
<WACI_CustomerExt>
<type>model</type>
<class>waci_customerext/observer</class>
<method>customer_register_success</method>
</WACI_CustomerExt>
</observers>
</customer_register_success>
</events>
</frontend>
The observer is configured to call the customer_register_success method of your WACI_CustomerExt_Model_Observer.
Implementing the Observer Method
In your namespace/module/group/Observer.php, you need to properly implement the customer_register_success method. Here’s how you should structure it:
<?php
require_once('../../../../../Mage.php');
class WACI_CustomerExt_Model_Observer
{
public function __construct()
{
// Construct any dependencies if needed
}
public function customer_register_success( Varien_Event_Observer $observer )
{
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('notify_new_customer');
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
$templateSubject = 'New customer registered';
// Set the sender details and template subject
$emailTemplate->setSenderName($senderName)
->setSenderEmail($senderEmail)
->setTemplateSubject($templateSubject);
// Retrieve the newly registered customer data
$customerData = $observer->getCustomer()->getData();
// Send the email using the prepared template and customer data
try {
$result = $emailTemplate->send(Mage::getStoreConfig('trans_email/ident_general/email'), $customerData);
Mage::log("Admin notification sent successfully for new customer: " . $customerData['email']);
} catch (Exception $e) {
Mage::logException($e);
}
}
}
In this implementation, we first load the default email template using its identifier (notify_new_customer). We then retrieve the sender details from Magento’s configuration settings and set them on the email template.
Next, we get the data of the newly registered customer via the event observer and prepare it to be sent as an array in the email.
Finally, we send the email using the prepared email template and customer data. If any exception occurs during this process, it is logged for debugging purposes.
Creating the Email Template
Your local/en_us/template/notify_new_customer.html file contains the HTML content of the admin notification email:
New customer registration:<br />
Name: {{var name}}<br />
Email: {{var email}}<br />
... you win a pickle.
This template uses Magento’s built-in email variable syntax ({{var variable_name}}) to insert the customer’s name and email into the email body.
Final Considerations
Ensure that your configuration is set up correctly:
- Make sure the observer model path in
config.xmlmatches the actual location of your observer file. - Verify that the sender email addresses (
trans_email/ident_support/emailandtrans_email/ident_general/email) are configured properly in Magento’s admin interface. - Check if there are any missing dependencies or errors in your observer method.
If you still encounter issues, make sure to enable logging in your Magento installation by setting the following configuration:
php -f Mage.php -- log 2 > /dev/null
This command will enable detailed logging for better debugging of any potential issues with your email sending process.