Why is Magento not sending emails?
You might come across this error several times, but you do not know how to get rid of it.
Fortunately, we provide a complete tutorial here so that you will not have to search for why is Magento not sending emails any longer.
Methods of Sending Emails in Magento
Table of Contents
There are two methods to send emails in Magento 2:
– Sending emails by queue: All the data of emails that haven’t been sent will be saved into the 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 the Release note, from Magento 1.9.1, all of the emails, including confirmation emails and transaction emails, are set to queue and sent based on cronjob configuration. Therefore, you need to set up a 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 controllers of the added modules via the default email send 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.
>>> If you need a comprehensive guide for setting up Magento 2 emails, this blog is for you: Magento 2 Email Settings: Easy Step-by-Step Tutorials to Master
When Is Magento Not Sending Emails and How to Fix?
#1. Check configuration on admin page
The first reason for Magento not sending emails can come from the incorrect configurations in the backend. This situation can block email delivery.
To check the configuration on the admin page, you can follow this sequence:
Store –> Configuration –> Advanced –> System –> Mail Sending option.
At “Disable Email Communications” option, let’s choose “No”.
Ensure that the Host and Port fields are correctly configured if you’re using an external mail server.
Go to Stores -> Configuration -> Sales -> Sales Emails
Under General Settings tab, choose Asynchronous sending to Disable
Under Order tab Enabled to Yes
Don’t forget to clear/refresh your cache.
#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 the causes of the error. Previously, you can also check system.log and excepton.log files (Remember to go to System/Configuration/Developer to enable the log function)
Some modules also have their own log-enabling function (and write into a separate 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. Below 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 a 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 -e. Now, 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 to cpanel and click on the icon of Cron jobs
- If there are cronjobs already:
- If a new cronjob needs to be set up:
3.3. Check by waiting cron to be executed
Open cron.php file and add these lines to 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 a 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 your store is installed in different Magento 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 functions in Mage_Core_Model_Email_Template. In that case, we must fix the code to eliminate conflicts or disable a module.
>>> In case you will need: Magento Tutorial For Beginners [2024 Update]
Conclusion
In conclusion, resolving the issue of Magento not sending emails requires checking several key areas such as cron job configuration, email queues, SMTP settings, and server restrictions. By understanding whether to send emails through a queue or directly, you can choose the best method for your store’s needs. Implementing the right fix ensures seamless communication with your customers and improves the overall functionality of your Magento store.
Please vote or share if you find this one useful. Or feel free to let us know your problems HERE. Backed by a dedicated support team, BSS Commerce ensures you receive top-notch service and solutions tailored to your specific eCommerce needs.
As many people also search for Magento 2 not sending emails, we will update you with the tutorial to fix “Why is Magento 2 not sending email?” later on.