Thursday 24 December 2015

How to implement mail system in your custom magento module


First Add new Template in Magento Admin > System > Transactional Email > Add New Template.
For Customer Registration load default registration Template from Local, modify as requirement then save it.

Use below code in your save function of module controller where you need.




$customer = Mage::getModel('customer/customer')->load($customer_id);

$templateId = 9; /* get template ID from magento admin > System > tramsactional Emails */
$sender = Array('name' => Mage::getStoreConfig('trans_email/ident_sales/name'),
'email' => Mage::getStoreConfig('trans_email/ident_sales/email'));

$password = '123Q3!34'; /* generate random password */
$email = $customer->getEmail();
$customer_name = $customer->getFirstname().' '.$customer->getLastname();

$emailName = $customer->getFirstname();
$vars = Array('customer_name'=>ucfirst($customer->getFirstname().' '.$customer->getLastname()),'customer_password'=>$password, 'customer_email'=>$customer->getEmail(),);
/* Note : variables should be  same as in Template */

$storeId = Mage::app()->getStore()->getId();
$translate = Mage::getSingleton('core/translate');

$mail = Mage::getModel('core/email_template');

$mail->addBcc($BCCMail);
$mail->sendTransactional($templateId, $sender, $email, $emailName, $vars, $storeId);

No comments:

Post a Comment