This is a continuation of the thoughts presented in the article “Testing the wp_mail Function.” That article focused on how to actually check your WordPress email configuration with direct test of the wp_mail function to be sure that the function itself is working. This is a good place to start if you are troubleshooting because if the function itself is not working, you need to track that down first.
If you have determined that wp_mail is operable, it is then probable that emails are being generated. Knowing this, the next step is to consider other elements of your WordPress email configuration to track down why emails are not being sent or received.
Understanding script based email
In order to determine what your problems might be, it is important to understand the potential email configuration requirements. Some issues could be server-based, others could be not understanding restrictions by your host.
What are your host’s email policies?
Valid email accounts
The first thing to know is what your host’s policies are for sending email via web scripts. If you spend a lot of time trying to track down problems before even knowing if you are in compliance with your host’s email policies, you could be wasting a lot of time.
Valid email headers
Some hosts require that any server-side email script send with a “from” address that is an actual email address. This may seem basic, but I’ve had a lot of support inquiries that didn’t bother to check this. WordPress by default sends email from a generic address “[email protected]”. If your host has a requirement that you send from a valid email address and you don’t have a [email protected] email configured, then your site can’t send email.
This isn’t a requirement with all hosts, but you should check to see if it is a requirement of yours. If this is a requirement, there are some things you can do to change the default “from” address. See the following:
Another commonly overlooked issue that is similar is that some hosts require you send with a valid “from” header. Again, the WordPress default configuration doesn’t cover this – it sends email without headers.
There are other headers that can help prevent your message from being rejected as spam. Making sure that the return-path header is not only a valid address, but matches the “from” address will take you a long way in this regard. And you can take care of this either by sending through an SMTP server or just filtering the phpmailer to make this match your “from” address.
Are you on a shared server?
In general, on shared hosting, the email process is shared, too. If another user on your host has a script that is tying up the email server, that is going to effect your site (and therefore your email script).
For those running WordPress on shared hosts, the issue most often is that email is delayed (sometimes significantly), not that it is inoperable. But it is important to know if this is something you are likely to be effected by. Just because someone doesn’t receive a message within seconds does not by itself mean that the message is not being sent. It could be delayed.
What about spam filters?
Sometimes, the issue is that certain messages are simply blocked because of an addressing issue. Emails coming into one of the major email provider domains (hotmail, aol, gmail, yahoo) can get flagged for a number of reasons.
If email from wp_mail is not getting delivered, you may need to consider is it not getting through to everyone? Or is this limited to certain domains? Getting blocked or blacklisted by a specific host could be an issue.
An easy solution
The simplest way around all of this is to use a valid email account sent through an SMTP server. SMTP stands for Simple Mail Transfer Protocol and sending through an SMTP server simply means you have set up a real email address on your system and you are allowing the web based script (wp_mail) to connect to the server with appropriate account credentials. This will satisfy most hosting requirements and also help you avoid system bottlenecks on shared hosting.
My usual solution for this is a plugin called WP Mail SMTP. There are a few other plugins out there for this purpose as well. Although not as popular (yet) as WP Mail SMTP, Easy WP SMTP looks promising. Another is WP SMTP. Using one of these plugins is an easy way to change your WordPress email configuration to send email via SMTP.
Of course, if you’d like to do it without a plugin, you can do that without too much trouble as well.
No matter which way you choose to approach it, SMTP is a more reliable and more stable way of sending email through WordPress.
For more information on testing, troubleshooting, and changing your WordPress email configuration for wp_mail, here are some additional posts:
- Testing your WordPress email settings for the wp_mail function – some information on wp_mail and a testing script you can use to make sure it is sending messages.
- WordPress Email Settings: Changing the wp_mail address with a simple plugin – here is a very simple and lightweight script you can load as a plugin to change the email address that WordPress sends email from.
- Changing the wp_mail from address in WordPress without a plugin – provides a simple code snippet you can use to change the email address that WordPress sends from, no plugin required.
- Easy SMTP email settings for WordPress – how to change your WordPress email configuration to send email from a valid SMTP server with a simple script, no plugin required.