Most people are generally unaware of how the WordPress wp_mail function works, how their hosting plan plays a role in tracking down email issues, and what to do to fix things so wp_mail sends email with some reliability. This article discusses how to track down some common problems sending email with wp_mail, how to troubleshoot wp_mail, and some simple solutions to common issues.
What is wp_mail?
wp_mail is the function the WordPress uses to send email.
This function is essentially a wrapper for the PHPmailer class, a php class that allows sending of email via php script. It also happens to be a pluggable function, which means that you can create your own mail function and replace wp_mail altogether (but that’s a fairly advanced project).
A large number of plugins rely on this function since it is a part of WordPress. So when things don’t work right, it can be difficult to track down the real issue if you don’t know where to start.
Between my own personal troubleshooting and handling support needs of my plugin customers, I have accidentally become a wp_mail expert (and am now one of the component maintainers for the Mail component in WP Core). I have several posts and articles about troubleshooting wp_mail, as well as fixes and solutions to common problems.
How do I know wp_mail is working?
If you have trouble with WordPress not sending email, it is important to know if wp_mail is working. If you don’t know whether the function is able to send email, then you don’t know if your plugin is broken, if it’s a WP problem, of if it’s something after that (such as with your host’s sending process).
I have written a simple test script to see if WordPress can actually send email. This is helpful for troubleshooting. If wp_mail is functioning, then you know the problem lies elsewhere; but if you can’t get a valid email sent, that can tell you a lot, too.
What can I do if it’s not working?
If wp_mail is not sending emails, then you need to figure out why. This can be the result of hosting requirements and restrictions, shared server issues, and other things.
I’ve put together a post that has more information on understanding script-based email and what some of the issues can be. Some of the problem might be requirements with your host.
What are the possible solutions to problems with wp_mail?
The easiest is, in my opinion, the best solution: Use SMTP to send email. An SMTP server is an actual email server. Sending email using a real account through an actual email server makes your site’s email process much more robust. This is much more reliable than using your webserver’s process for sending script-based email.
I have put together a post on how to handle this without a plugin. It is not a difficult process, and I use the method a lot.
A simple solution is of course to use a plugin – and there are several for doing this. I recommend WP Mail SMTP. This plugin is used on over a million sites, and I’ve been recommending it for over a decade (LONG before they had an affiliate program). Many of my WP-Members users use it for making their site’s email more robust. Get more information on WP Mail SMTP here.