By default WordPress uses the PHP mail() function to send emails. This is very simple to work with but sometimes the function is blocked by hosts or other mail servers may block mails sent via it (because you don’t have to login to use it). When you are debugging WordPress email issues the first thing to establish is whether the emails are being sent.
A few years ago I wrote a small plugin to log emails sent.
Aside: The debug2log() function is in another of my small plugins. It writes to a wp-content/debug.log file. I wrote that code before I found out about WP_DEBUG and WP_DEBUG_LOG.
The plugin doesn’t check whether the email was sent. There is a ‘wp_mail_failed‘ hook that I could use to get error messages. If I could figure out how to trigger a failure then I could write some code and test it.
Using the Plugin
This plugin came in very useful recently when helping a friend debug email issues on his client’s WooCommerce site. The order emails were being sent to the customer but not to the admin. The admin has a yahoo.ie email address.
I installed and activated my plugin. I also activated my plugin to redirect admin order emails and made a test order. I received the order email to my primary email account (damiencarbery.com) but the admin order email did not arrive at my yahoo.com account.
I could see from the log that the email was being sent. The To and From were as expected.
I next wrote a quick plugin to send a simple plain text email when a page was viewed (it is a low traffic site so I would not be receiving many emails) and I visited the site again.
This time I received the test email. I suspected that the issue is with HTML emails so I created another plugin to send a html email. Surprisingly this went through.
It is generally recommended that SMTP be used to solve WordPress email issues. Unfortunately the client’s web host charges to use authenticated SMTP on their servers so I will be trying other ideas before asking the client to pay for this option.