
Now and then you may wind up sending an email after a specific activity has happened. For instance, you have a custom module that permits you to add an item to a rundown of top picks and might want to email the client that their rundown has been upgraded. While working with Magento, I have ended up doing this frequently. In the wake of counseling with my kindred designers, I discovered how to send messages automatically in Magento.
Searching for the most fundamental approach to programatically send messages in Magento? Here's the manner by which:
<?php
// Send mail, the Magento way:
require_once('app/Mage.php');
Mage::app();
// Create a simple contact form mail:
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('contacts_email_email_template');
$data = new Varien_Object();
$data->setData(
array(
'name' => 'Test',
'email' => 'test@test.com',
'telephone' => '1234567890',
'comment' => 'This is a test message'
)
);
$vars = array('data' => $data);
// Set sender information:
$storeId = Mage::app()->getStore()->getId();
$emailTemplate->setSenderEmail(
Mage::getStoreConfig('trans_email/ident_general/email', $storeId));
$emailTemplate->setSenderName(
Mage::getStoreConfig('trans_email/ident_general/name', $storeId));
$emailTemplate->setTemplateSubject('Test mail');
// Send the mail:
$output = $emailTemplate->send($_GET['email'], null, $vars);
var_dump($output);
?>
Save it in a file called mailtest.php, and simply call it in the browser like this:
http://www.yourdomain.com/testmail.php
Presently you ought to see a true - message when Magento could send the mail and false if not.




