>Magento Emails Not Being Sent: How To Fix

Magento Emails Not Being Sent: How To Fix

I. Methods of sending emails in Magento

Basically, there are two methods:

– Sending emails by queue: All the data of emails that haven’t been sent will be saved into database (table core_email_queue and core_email_queue_recipients). When the queue gets its turn, those data will be matched and sent. According to Release note, from Magento 1.9.1, all of emails,  including confirmation email and transaction emails, are set to queue and sent based on cronjob configuration. Therefore, you need to set up cron in order that your online shop can send emails in a smooth way.

 – Sending emails directly: Usually, sending these emails is activated in event observers or controller of added module via default mailsend function of php or Zend_mail. Because emails are not sent by queue, we can debug code more easily and conveniently when errors are reported.

II. When Magento is unable to send emails

1. Check configuration in admin page

To do that, you can follow this sequence: System –> Configuration –> Advanced –> System –> Mail Sending option. At “Disable Email Communications” options, lets choose “No”.

2. As for emails not being sent by queue

2.1. Check server configuration

Try running this: 

<?php
mail ('you@example.com', "Test Postfix", "Test mail from postfix");
?>

in which: you@example.com is your email address. If you don’t receive any email, that means you need to check server settings

2.2. Find errors in email sending process

During doing debug, we should place the code for sending emails in try{….} catch….. and print out exception message to know causes of the error. Previously, you can also check system.log and excepton.log files (Remember to go to System/Configuration/Developer to enable log function)

Some modules also have their own log enabling function (and write into a seperate file). Aschroder’s SMTP Pro, for example.

3. As for emails using queue

In order to run cyclical sending, emails using queue need to wait until cronjob is set up. Belows are the ways how we can check it

3.1. Check and Setup by SSH

Log in SSH cient and type crontab -l. If there is cronjob leading to cron.php file or cron.sh then the result will show up:

If cronjob needs to be re-setup, we type crontab -eNow, edit cronjob window appears. When fixing content is done, press Ctrl+O to save, then Ctrl+X to exit

3.2. Check and setup by cpanel

Log in cpanel and click at the icon of Cron jobs

– If there is cronjobs already:

 – If new cronjob needs to be set up:

 3.3. Check by waitng cron to be executed

Open cron.php file and add these lines into dispatchEvent part

Mage::dispatchEvent('default');
$log = fopen(__FILE__.'.log', 'a');
fwrite($log, date("Y-m-d H:i:s").PHP_EOL);
fclose($log);

So, each time cron file is run will make log cron.php.log in var/log and by checking that point of time we can come to the conclusion.

3.4. Check conflicts among modules

When Magento is installed different modules at the same time to support sending emails, they may conflict and cause errors. For instance: Using SMTP Pro (old version) and Mailchimp together will make sending emails impossible because they both overwrite and extend function in Mage_Core_Model_Email_Template. In that case, we must fix the code to eliminate conflicts or disable a module.

Please vote or share if you find this one useful. Or let us know what you think about it in the comment below.

< Previous Post
Next Post >