Have you ever been in the situation where you need to quickly check if your Magento-site is still sending e-mails? You know you can just send a mail by using PHP’s mail()-command, but of course, you need to check if Magento is able to send e-mails. After all, you never know how Magento’s internal e-mail settings are configured, so it’s best to send a mail the Magento-way.
So I wrote this little script that you can place in the root of your site:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?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); |
Save it in a file called mailtest.php, and simply call it in the browser like this:
1 |
http://www.yourdomain.com/mailtest.php?email=your-address@domain.com |
Now you should see a true -message when Magento was able to send the mail and false if not. Please note that ‘true’ means that in the very end, PHP was able to send the mail. So if the mail is not arrived the problem lies somewhere else (spamfilter? SPF records? who knows…), but not with Magento.
Visitors give this article an average rating of 4.6 out of 5.
How would you rate this article?
★ ★ ★ ★ ★
Very handy script thanks!
I’ve been having no end of troubles with magento emails…
If i run this script it’s returning true, and turning up in my mail-
but when i try to send order emails nothing…
have cron setup, scheduler working away, but the kicker is even pressing the “send email” button on a previous order does not result in any emails sent –
It’s my understanding no cron is required for those emails send from a sales order screen like that-
i got the same problem. the script returns true and e-mail is received, but any magento created by magento aren’t working.
i got bool(false) how to resolve it. any help /suggestion please Thanks
Nice script, thanks!
I am having email issues with magento. However, when I use this script and put it in the public_html folder of the server, magento redirects to a 404 page. Can anybody please help and let me know how to stop the redirect to the 404 page? Thanks
i got bool(true) and e-mail is received.
But how can i solve this magento issue
2016-02-25T11:59:14+00:00 ERR (3):
exception ‘Zend_Mail_Transport_Exception’ with message ‘Missing To header’ in /lib/Zend/Mail/Transport/Sendmail.php:182
any solution for this?
What to do next if it returns “bool(false)”?
Amazing solution@ Thanks a lot
it returns “bool(false)” What to do next?