Testing your WordPress email settings for the wp_mail function

WordPress has its own email function, wp_mail, that it uses for sending email.  There are many plugins, my WP-Members plugin included, that rely on this function to be working properly.  WordPress does not provide email settings, so how do you know if this function is working?

Suppose you have some plugins or something in your site that should be sending you emails and you are not receiving any emails. Is something broken in the plugin? Or is it a case of wp_mail not functioning properly? You can’t begin to track your issue until you know where to be looking.

This article will explain how you can run a test script on your site in order to test  your WordPress email settings to see if the wp_mail function is working and sending email.

The wp_mail function accepts the following arguments:

  • $to (required) – This is the email address you wish to send to
  • $subject (required) – The email subject line
  • $message (required) – The email message body content.
  • $headers (optional) – This is an optional argument. It could contain things like defining plain text or html email, or the “from” name of an email
  • $attachments (optional) – Another optional argument.  This one allows for an email attachment.

In general, you need to focus on the first three required arguments.  If things work OK with those, wp_mail is functioning.  If not, further testing may require looking into the $headers a little more.  Some hosts require that valid “from” headers be used, so that is something that should be checked.

I’ve put together a simple little script that allows you to test your WordPress email settings by attempting to send an email through the wp_mail function.  To use this testing script, save it as a php file and load it to your WP root directory via FTP.

Set your email address as indicated in the example script, save the file as mailtest.php, then browse to it directly in your browser to fire the wp_mail function  (http://yourdomain.com/mailtest.php).  You will get a result on screen, and if all is functioning, you will receive a test message in your email inbox.  If you get an error message or you don’t receive the email, then you know there is an issue with wp_mail.

Here is the script. I plan to put this together in a utility plugin at some point in the future, but for now, you can save it as a php file and run it from your WP root folder.

Now, this post and this script are focused on determining if wp_mail is working.  Troubleshooting is another matter altogether.  For some next steps, this post has some things to know when troubleshooting wp_mail, and it includes some possible solutions.

For more information on testing, troubleshooting, and changing your WordPress email configuration for wp_mail, here are some additional posts:


  1. Irwin Lawson says

    Hi there,
    I have tested your plugin on one site and it works really well.
    However I tested it on another that is having a problem using wp_mail and it does not work.
    This problem (wp_mail not working) is so hard to solve.
    I have been using a plugin “configure smtp” on this site to get mail to work, and it does.
    Is there a way i can hook into this?

    • says

      A lot of users have had success using WP Mail SMTP. Depending on your host, it could be that you need validated SMTP to send email from a php script. That’s the plugin most users use in that situation.

  2. says

    Hi Chad,

    Seasons greetings!

    I’m trying to add the WP-Members plug in to several pages that I’ve individually blocked at my blog. Several visitors have registered at http://reloroundtable.com/blog/wikisresearch/available-tonnage-lists/ but have reported that they never received the email verification containing the password as confirmed in the dialog box they received when they completed the form.

    I tested the native wp_mail funtion by creating a new user via the WP admin panel after disabling another plugin that uses the same native WP mail function. The new user registration worked both times I tested it.

    What could be creating the hang up if wp_mail is working the way it’s supposed to? I couldn’t find any mention of the same problem in the WP support forums

    Thanks in advance for any help you can offer! ~ Eric

    • says

      The most common issue is that people actually get the email, but they either overlook it, or it ends up in spam, or some other issue that would be entirely out of your control. If you are getting “intermittent” reports on email issues from users, I would say that’s the most likely.

      If you’ve tested things yourself and things are not working, then I would start with trying smtp authenticated mail. The WP Mail SMTP plugin does this well.

      If it’s not one of those things, the last thing would probably be if you are using a cache plugin, that something is not configured to accommodate inline registration. But the previous two items are your more probable issues/resolutions.

  3. Sana says


    I have tried your code and I am not able to send email. What could be the problem? SMTP port is set on php.ini and I am checking it on localhost. The comments panel send email but when I try manually with wp_mail, it doesnt work. Please help me out

  4. valerie says

    thanks for the script and insightful post.
    I now have the reverse problem: I finally found a plugin that is successfully using wp_mail, but your testscript does not work and I’m trying to find out why. I tried copying the headers that are used by the working plugin into the test script but without success.
    What else could I be doing wrong? (all the native WP emails also get sent properly)
    I’d really appreciate any hints, I’m trying so hard to understand the mysterious workings of wordpess… :(

  5. says

    It work!!! I spent a couple of hours trying to make my form work.
    I tested a few plugins for forms and smtp, emails exchange with cs from hosting and theme providers… and finally this simple and clean solution made a trick:) .
    Thank you!

  6. CSL says

    Looks like a typo in the sample code, the call to wp_mail returns a result to send_message but the var sent_message is the one being checked.



Join in the discussion