Magento: Send Transactional Email using Programmatically
In Magento, Transactional Email Templates can be created from System -> Transactional Emails. This article shows
how we can send transactional emails programmatically.
There are few necessary things for any transactional email in Magento. They are:
- Template ID = ID of your transactional email template
- Sender Name
- Sender Email
- Recepient Name
- Recepient Email
- Store ID = Current user’s store ID
- Vars = Variables to use in transactional email template
<?php public function sendTransactionalEmail() { // Transactional Email Template's ID $templateId = 1; // Set sender information $senderName = Mage::getStoreConfig('trans_email/ident_support/name'); $senderEmail = Mage::getStoreConfig('trans_email/ident_support/email'); $sender = array('name' => $senderName, 'email' => $senderEmail); // Set recepient information $recepientEmail = 'john@example.com'; $recepientName = 'John Doe'; // Get Store ID $store = Mage::app()->getStore()->getId(); // Set variables that can be used in email template $vars = array('customerName' => 'customer@example.com', 'customerEmail' => 'Mr. Nil Cust'); $translate = Mage::getSingleton('core/translate'); // Send Transactional Email Mage::getModel('core/email_template') ->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId); $translate->setTranslateInline(true); } ?>Hope this helps. Thanks.
Pritesh
Pritesh Pethani