Quickly test if Magento can successfully send email

Submitted by deeperdata - 1 year 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.

<?php
// Magento e-mail tester.
if (!isset($_GET['email'])) {
    echo 'usage: mailtest.php?email=your-email-address@domain.com';
    die;
}
 
// 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' => 'Foo',
        'email' => 'foo@bar.com',
        'telephone' => '123-4567890',
        'comment' => 'This is a test'
    )
);
$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);
affiliate_link
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean