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 recipient email address.
- The sender email is the email/userId configured in the SMTP module (if available) or in the sendmail_path configuration of PHP.
- SMTP:
-
- Sendmail_path: Run Commandline:
php -i | grep sendmail_path
, admin@… is sender email
- Sendmail_path: Run Commandline:
dev@cli-blog_mail-docker: /var/www/html/blog-mail - - - - - - - - - - - - $ php -i | grep sendmail_path sendmail_path => /usr/sbin/sendmail -t -a mail -f admin@... - FAdmin
If you don’t receive any email, that means you need to check server settings:
- Check the reputation of the sender’s email and verify if it has been added to a blacklist using this site: https://mxtoolbox.com/emailhealth/.
- Solution:
- Properly configure SPF, DKIM, and DMARC on the DNS console of your domain registrar (Follow this guide: https://www.godaddy.com/help/enable-and-add-dkim-to-my-domain-for-microsoft-365-41748).
- To remove a block from a blacklist, submit a request to:
2.2. Find errors in email sending process
During debugging, we should place the code for sending emails in try{….} catch….. and print out an 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 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 to the SSH client and type crontab -l. If there is a cronjob leading to command cron:run or cron.sh, then the result will show up:
If cronjob needs to be re-setup, we type php bin/magento cron:install
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 the cron.php file and add these lines to the dispatchEvent part
Mage::dispatchEvent('default'); $log = fopen(__FILE__.'.log', 'a'); fwrite($log, date("Y-m-d H:i:s").PHP_EOL); fclose($log);
Each time a cron runs will make a log to table cron_schedule in the database and by checking that point of time we can conclude.
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.
Solution: Install only one SMTP module (e.g., Magepal, Mageplaza, Amasty) to avoid conflicts between multiple SMTP modules. Uninstall or disable any other SMTP modules to ensure smooth email functionality.
>>> 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.