Troubleshooting wp_mail WordPress Email Configuration

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

WordPress sends email using wp_mail, a function that for all practical purposes operates like php’s mail. It is a way for your site to send email via a PHP script.

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.  The problem with this is that the plugin has not been updated in over 2 years.  That could mean issues with more recent versions of WordPress (although at present that shouldn’t be the case) and also means you are likely on your own for support.

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:

Get Fresh Content Delivered

Join and get free content delivered automatically each time we publish.

Comments

  1. Paul says

    Ugh. I have been tearing my hair out all day, trying to get stupid WAMP on my stupid windoze 7 machine to just send an email through my (locally hosted) WordPress site. It works perfectly on my Mac (through MAMP). I have installed (and uninstalled) numerous SMTP plugins, spent hours working my way through pages of ridiculously complex code…blah blah blah php…..blah blah blah Apache…blah blah SMTP….THERE MUST BE A SIMPLER WAY!

    Do you happen to know if any of the other Windoze-based WAMP/XAMP/etc. bundles fix this bug? Or is it just another bug inherent in the OS?

    Also, most people suggest something along the lines of “changing the address WordPress sends emails from”. But I’m using the ‘Contact Form 7′ plugin so people can (once it’s live) send ME emails from THEM, and obviously I want the email to come from THEM, not some other email address.

    Is the best policy to just write off today as a very annoying waste of time, uninstall WAMP, throw my stupid (but VERY expensive, high-end) Windoze machine in the bin and go back to my trusty, slow old Mac/MAMP?

    Or do I just live dangerously and assume that the email system will (might, probably, hopefully) work OK once it’s uploaded to an online server?

    So, if you have any suggestions that don’t involve me spending weeks recoding my entire PC from the ground up, I’d be very, very grateful!

    Sorry for the ranting, and thanks in advance if you happen to have any suggestions!

    Paul

    • says

      Hi Paul,

      The issue for you isn’t so much configuring wp_mail, but rather configuring a mailserver, which for most people is probably more complicated. If you use some packaged development system such as a XAMP or WAMP, you aren’t going to have email throughput configured automatically.

      If you do a lot of development work, it probably does make sense to learn how to configure this so you can test locally. If this build is a one-off, then I personally wouldn’t take the time. I’d do any email work when I moved the server. Up there your issues are far smaller because the email system should already be configured for you; in which case you only need to worry about making sure your sending process for wp_mail meets your hosts requirements (something you could find out in advance by asking your host).

      • Paul says

        Thank you for your quick reply! Yes, as you suggested, I think I’ll skip the mailserver part and check it once it’s online. It’s really very annoying, though, and I’m surprised nobody seems to have included some kind of auto-setup-mailserver in a WAMP/XAMPP installation. I’m sure many people would happily pay for this feature.

        – Paul

  2. Paul says

    Oh well, that optimism was short lived.

    The main thing I needed to do today, before I wasted over 7 hours on this email thing, was configure the Events Manager plugin on my WordPress site. So, having just abandoned the email thing, I created a test booking, but of course, it sends a confirmation email, and therefore generates an error. Well, as a development platform, WAMP and windoze absolutely sucks. I’m now in two minds, do I spend the next god-knows-how-long unnecessarily learning all sorts of pointless junk about mailservers, or do I go back to my slow Mac? I knew windoze was awful to use, but never knew it was pretty much useless for any kind of serious work. I’ve used Macs all my life and have just forked out a ton of cash on a false-economy windoze machine, which I hate more and more every day.

  3. says

    Hey Paul,
    I have an interesting problem that has stumped me. It all started about two weeks ago. All my plugins stopped sending emails. I receive nothing – from contact forms (Gravity Forms) to WP-Courseware to WishList Member. They were going out fine before with the exception of an occasional plugin problem.

    I added a couple of plugins WP-Mail-STMP to Check E-mail. Tried many different mails – nothing received. Interestingly – Bool=true every time.
    I’ve change the default from email, etc.

    I have deactivated all the plug ins reactivated, etc.

    So, I thought – must be a server issue. Created a testmail.php page – email goes through just fine – which tells me that it is not a server issue.

    Any thoughts on troubleshooting? What I might have missed?

Trackbacks

Join in the discussion