Deliver emails reliably by using SMTP. Use a tiny streamlined plugin to keep things fast.
Reliable delivery of emails is a topic that comes up regularly in WordPress Facebook groups, especially in the Advanced WooCommerce group. Not receiving new order emails and customers not receiving order emails is very frustrating and could cost store owners future business.
The suggested fixes include using an email service like Mailgun, Mandrill or sending emails via SMTP through your email or hosting provider. My first suggestion is to determine whether the emails are being sent – I use my email logging code to establish this. If the emails are being sent by WordPress then the issue is further down the line. They could be blocked, or rejected by the outgoing email server or, more likely, by the destination email server.
Local install not sending emails
I use XAMPP for local development. I like being able to step through debugging when necessary. I didn’t install the sendmail component so emails from my local WordPress installs were not going anywhere. Reading raw html emails in debug logs is tedious so I went looking to send them via my web site host’s SMTP servers.
You should be able to use SMTP for free and you can install one of the many SMTP plugins to do this. I chose to write a tiny plugin to do this so that it would be as streamlined as possible.
I read through the code for wp_mail() and eventually figured out that I could use the ‘phpmailer_init‘ filter function. I did my usual experiments to find out what was being passed to the filter function.
I knew the SMTP settings for my host and put them into the function. I put this code in my ‘mu-plugins‘ folder so that it cannot be accidentally deactivated.
You can send a test email e.g. send one on each page load. Copy that code into the ‘mu-plugins‘ folder and then reload your website front end. Then delete it so that you don’t get flooded with emails.
I also suggest sending an email to the Mail Tester site. In their words, it will ‘Test the Spammyness of your Emails‘. It will check DKIM and SPF records and examine the content of the emails. It’s a simple way to see what steps you need to make to increase the chances that your emails arrive in inboxes.