Quickly test if Magento can successfully send email

Submitted by metaharper - 6 years ago

After a recent Magento site migration from one host to another, I noticed that I wasn't getting emails from Magento after testing the newsletter sign-up and order confirmation. As it was a new client with a rather complex email arrangement, it was best to determine if the emails were breaking due to a server configuration issue or something else entirely. I found this great script (credit: https://gielberkers.com/test-e-mails-working-magento/) which does exactly what I needed. No need to reinvent the wheel! Enjoy.

// Magento e-mail tester.
if (!isset($_GET['email'])) {
    echo 'usage: [email protected]';
// Send mail, the Magento way:
// Create a simple contact form mail:
$emailTemplate = Mage::getModel('core/email_template')
$data = new Varien_Object();
        'name' => 'Foo',
        'email' => '[email protected]',
        'telephone' => '123-4567890',
        'comment' => 'This is a test'
$vars = array('data' => $data);
// Set sender information:
$storeId = Mage::app()->getStore()->getId();
    Mage::getStoreConfig('trans_email/ident_general/email', $storeId));
    Mage::getStoreConfig('trans_email/ident_general/name', $storeId));
$emailTemplate->setTemplateSubject('Test mail');
// Send the mail:
$output = $emailTemplate->send($_GET['email'], null, $vars);
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean