I would like to send an email notification to my store's contact email address every time when a new customer has been Registered.
I don't want to purchase any kind of the extensions, so please help me to do this
Thanks in advance
Best practice is to use Magento's event system.
app/etc/modules/Your_Module.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Your_Module>
<active>true</active>
<codePool>local</codePool>
</Your_Module>
</modules>
</config>
app/core/local/Your/Module/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<global>
<models>
<your_module>
<class>Your_Module_Model</class>
</your_module>
</models>
</global>
<frontend>
<events>
<customer_save_after>
<observers>
<your_module>
<type>model</type>
<class>your_module/observer</class>
<method>customerSaveAfter</method>
</your_module>
</observers>
</customer_save_after>
</events>
</frontend>
</config>
app/code/local/Your/Module/Model/Observer.php
<?php
class Your_Module_Model_Observer
{
public function customerSaveAfter(Varien_Event_Observer $o)
{
//Array of customer data
$customerData = $o->getCustomer()->getData();
//email address from System > Configuration > Contacts
$contactEmail = Mage::getStoreConfig('contacts/email/recipient_email');
//Mail sending logic here.
/*
EDIT: AlphaCentauri reminded me - Forgot to mention that
you will want to test that the object is new. I **think**
that you can do something like:
*/
if (!$o->getCustomer()->getOrigData()) {
//customer is new, otherwise it's an edit
}
}
}
EDIT: Note the edit in the code - as AlphaCentauri pointed out, the customer_save_after
event is fired for both inserts and updates. The _origData
conditional logic should allow you to incorporate his mailing logic. _origData will be null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With