Magento not sending emails

[Solved] Magento Not Sending Emails: How To Fix?

by Lily Tran

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

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”.

Magento 2 mail sending settings

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

Magento Sale Emails Settings

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:

sign in SMTP

    • Sendmail_path: Run Commandline: php -i | grep sendmail_path, admin@… is sender email
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:

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:

Check and Setup by SSH

If cronjob needs to be re-setup, we type php bin/magento cron:install

re-setup cronjob

3.2. Check and setup by Cpanel

Log in to cpanel and click on the icon of Cron jobs

    • If there are cronjobs already:

magento emails not being sent - Cron Job Issues

      • If a new cronjob needs to be set up:

magento not sending email - setup cron job 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.

Check by waiting cron to be executed

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.

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.