
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 problems.
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. wp mail is also 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 the function is able to send email, then you don’t know if your plugin is broken, if it’s a WP problem, or if it’s something such as 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.
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 along with some possible issues. 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 runs on more than one million sites. I have recommended 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.
Enjoyed this article?
Don't miss a single post. Subscribe to our RSS feed!