Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Send Email in WordPress using the Gmail SMTP Server

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Send Email in WordPress using the Gmail SMTP Server

Are you having trouble sending emails from your WordPress site? One easy way to solve this is by sending emails from WordPress using the Gmail SMTP server. In this article, we will show you how to send email in WordPress using the Gmail SMTP server.

Send WordPress emails using Gmail smtp servers

Why and When You Need Gmail SMTP Server for WordPress Emails

Your WordPress site sends emails to notify you of new user registration, lost password reset, automatic updates, and even notifications from your contact forms.

By default, WordPress uses the PHP mail function to send out email notifications. However this function does not work as expected due to a number of reasons.

Most WordPress hosting companies restrict usage of this function to prevent abuse and spam.

Spam filters on popular email service providers check incoming emails to monitor if they are sent from an authentic mail servers. Default WordPress emails fail this check and sometimes may not even make it to the spam folder.

SMTP (Simple Mail Transfer Protocol) is the industry standard for sending emails. Unlike PHP mail function, SMTP uses proper authentication which increases email deliverability.

Gmail provides SMTP service that you can use to send out emails from your WordPress site. If you just want to send WordPress notification emails to yourself and few users on your site, then Gmail SMTP servers are the best option.

However, if you are planning on sending newsletter emails using WordPress, then you should use a mass emailing service provider, like MailGun or SendGrid.

Free vs Paid Gmail SMTP Service for WordPress

You can use your free Gmail account to send out WordPress emails. However, for better deliverability, we recommend using paid Google Apps for Work with Gmail.

With Google Apps for Work, you get your own professional branded email address such as (yourname@yoursite.com).

Google Apps require you to add MX records to your domain name which means that your emails will appear to be coming from your own domain name boosting authenticity and ensuring better deliverability.

We use Google Apps for Work in our business, and can honestly say it’s the best.

To make it easy, we have created a video tutorial on how to send emails in WordPress using Gmail SMTP that you can watch below.

However if you just want to follow text-instructions, then you can follow our step by step tutorial on how to send emails in WordPress using Gmail SMTP.

How to Send WordPress Emails Using Gmail SMTP Server

If you decided to use Google Apps for Work, then you first need to set up your domain to work with Google Apps. We have a step by step tutorial on how to setup a professional email address with Google Apps and Gmail.

Rest of the instructions are the same whether you are using paid or free Gmail account.

There are two ways you can connect your WordPress site to Gmail SMTP servers.

The first method uses OAuth Authentication. This is a more secure method to send emails using Gmail Servers.

The second method is by allowing Gmail to be used with less secure apps. This method is not recommended because it’s less secure. You have to type in your gmail password in WordPress which is visible to all admin users. It should only be used if you are unable to use the first method.

Method 1: Setting up Gmail SMTP using OAuth Protocol

First thing you need to do is install and activate the Gmail SMTP plugin for WordPress. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Settings » Gmail SMTP to configure the plugin settings.

Gmail SMTP plugin settings page

You will see a notice that requires you to create a web application with your Gmail account to generate API keys. These API keys will authenticate your site’s use of Gmail SMTP servers.

Creating an App and Generate API Keys for Gmail

First you need to click on the web application link provided in the plugin settings to create an app.

This link will take you to Google Developers Console website. You need to sign in with the gmail account that you want to use for sending WordPress emails.

Once you are logged in, a new project will be created for you with the Gmail API enabled in it.

Gmail API Enabled

Click on the go to credentials button to continue.

On the next screen, you will be asked where will you be calling the API from? You need to select Web Browser (Javascript) from the dropdown. Under ‘What data will you be accessing?’, select User Data.

Add credentials to your web app

After that click on the ‘What credentials do I need?’ button to continue.

Gmail API setup wizard will now ask you to provide the URL of website authorized to use this API. Under ‘Authorized JavaScript origins’ you need to enter the URL of your website.

Under ‘Authorized redirect URIs’, you need to paste the URL shown on Gmail SMTP plugin’s settings page in your WordPress dashboard.

Next, click on ‘Create client ID’ button to continue.

You will now reach OAuth Screen setup. Simply select your gmail address and provide a name for the App that is accessing your Gmail Account. In this case, it will be your own website name.

Setup OAuith Consent screen

Once you are done, click on the continue button to proceed.

You have successfully setup Gmail API with OAuth authentication enabled for it. You need to click on the Done button.

Set up complete for Gmail API

Now you will see the list of client IDs (apps) that you have created to access your Gmail API.

Click on the name of your website or project client to continue.

Client IDs

On the next screen, you will see the Client ID and Client Secret keys.

API Keys

Simply copy the keys and paste them in your Gmail SMTP plugin’s settings page on your WordPress site.

Gmail SMTP plugin settings

After that fill out rest of the plugin settings. You need to add your gmail email address in OAuth Email Address and From Email Address fields. You can enter your name or the name of your website in the ‘From Name’ field. In our emails, we use Syed from WPBeginner.

Next, select TLS for encryption and use 587 as port. Finally, click on the save changes button to store your settings.

After the plugin’s settings page reloads, you need to scroll down to the bottom and click on the Grant Permission button.

Grant permission

This will take you to Google Accounts where you will be asked to give your website permission to access your Gmail account. Click on the allow button to continue.

You will be redirected back to Gmail SMTP plugin’s settings page on your WordPress site. You will notice the SMTP Status icon has now turn green.

SMTP connected

That’s all, you have successfully setup WordPress emails to be sent using Gmail SMTP server. You can now click on the test email tab and send yourself a test email message.

Method 2: Setting up Gmail SMTP with Less Secure Apps Enabled

This method allows Gmail to be used with less secure apps. This method is not recommended and should only be used if you can’t use the first method.

Since security and spam is a main concern for most email service providers, it is likely that Google may discontinue this method at some point in the future.

If you are using Google Apps for Work, then here is how you can allow users to manage their access to less secure apps.

Visit your domain’s admin dashboard for Google Apps. Next, go to Security » Basic Settings and scroll down to less secure apps section.

Less secure apps settings in Google Apps

Click on ‘Go to settings for less secure apps’ link to continue.

On the next screen, check the option next to ‘Allow users to manage their access to less secure apps’. Don’t forget to click on the save button at the bottom right corner of the screen.

Rest of the instructions are the same for both paid and free Gmail accounts.

Simply visit the less secure apps settings page in your Google account settings and turn on access to less secure apps.

Turn on Less Secure Apps in Google Settings

Now that you have enabled less secure apps to access your Google account, it is time to setup your WordPress site to connect with Gmail SMTP servers using the less secure method.

First you need to install and activate the WP Mail SMTP plugin.

Upon activation, you need to visit Settings » Email page to configure the plugin settings.

WP SMTP Settings

Here is how to fill out the plugin settings:

  • From Email: Enter your Gmail address.
  • From Name: Enter your name or title of your website.
  • Mailer: Select ‘Send all WordPress emails via SMTP.
  • Return Path: Check the box to use the From email as return path.
  • SMTP Host: smtp.gmail.com
  • SMTP Port: 465
  • Encryption: Use SSL encryption
  • Authentication: Yes, use SMTP authentication
  • Username: Your complete Gmail address, e.g. john@yourdomain.com or john.smith@gmail.com
  • Password: Password of your Gmail account

Click on the save changes button to store your settings.

After saving your settings scroll down to the bottom of the page, and you will see ‘Send a test email’ section. Enter an email address to see if everything is working fine.

That’s all, you have successfully setup your WordPress site to send emails using Gmail SMTP servers.

Troubleshooting Gmail SMTP Not Working Issues

We have seen issues of Gmail SMTP not working with certain shared hosting configurations.

Take the following steps to fix the Gmail SMTP issue:

  1. Login to your cPanel account and create an email account that matches your Google apps email address. This might seem strange because you’re not using your server, this step basically tricks your server into believing that you’re sending the email through the server.
  2. In your cPanel account, go to MX Records and change the MX routing from automatic to Remote. It might be a little tricky to find since each host now has custom cPanel interface, but look for a small link next to MX that says Email Routing: Remote Mail Exchanger.
  3. After that log back into your WordPress site and send a test email.

We hope this article helped you learn how to send email in WordPress using the Gmail SMTP server. You may also want to see our list of the 5 best contact form plugins for WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.


Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. Jason North says:

    I’m getting this error when I try to activate the plugin:

    Plugin could not be activated because it triggered a fatal error. Parse error: syntax error, unexpected T_FUNCTION, expecting ‘)’ in /home3/north23/public_html/forcebrain/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/autoload.php on line 19

  2. genie says:

    Hello, I use gmail-smtp plugin but it conflict with ultimate membership. Could you help me ?
    I try another wp mail smtp but in the last feld: user account pass. Google app not allow to login from plugin. Pls help
    Thank you

  3. Leslie Andrews says:

    Clearly I’m doing something wrong. When I get to “add credentials” I’m getting this error message and can’t move forward.

    Invalid Redirect: must end with a public top-level domain (such as .com or .org)

    Any help would be great

    • WPBeginner Support says:

      If you look at the URL closely, you will notice that you are missing a . between domainname and the TLD, yours is examplecom when it should be example.com.

  4. Graham says:

    Thanks for the tutorial, but I get this error when I try to send a test email:

    Connection: opening to ssl://smtp.gmail.com:587, timeout=300, options=array ()
    SMTP ERROR: Failed to connect to server: Connection refused (111)
    SMTP connect() failed.

    Does it have something to with my site being secured with SSL?

  5. Tom says:

    Nice Article, I’m having a few issues to get this working. So I Deactivated the Plugin and tested a Contact Form to see if all was the same before setting up Gmail SMTP, unfotunately No Emails are being sent through now.

    Even though the Gmail SMTP Plugin is NOT active, do we need to reset back to the default settings somehow?

  6. Jenny says:

    Hi,

    I have this all set up properly and the test email worked…I just commented on my own blog to see if I would get an email when a comment was posted but I unfortunately didn’t. Can someone help me figure out where I went wrong?

  7. Sachin says:

    Hey thanks for the tutorial. Everything works fine in Setup, but when mail is being sent the site freezes for about 5 mins. site doesnt open at that time. It doesnt respond at that time. Any idea what might be causing this issue. But the point is mail is sent at last finally

    • WPBeginner Support says:

      Please contact your WordPress hosting provider. They may be able to help you better.

  8. crissy says:

    Hi,

    I’m having problem with the test email send

    Fatal error: Cannot redeclare class phpmailer in /home/mywebsite/wp-includes/class-phpmailer.php on line 29

    please help

  9. David says:

    Hi, I just installed this plugin, and everything went perfectly–thanks to your excellent tutorial! (I definitely couldn’t have done it without you.) My website’s outgoing email immediately started landing in people’s inboxes rather than in their spam folders.

    But since I’m a novice at these matters and don’t know SMTP from RSVP, I did some reading on SMTP, and on one website I came across made this statement:

    “Another strategy that hackers use: If your app sends email using SMTP, the IP address will be recorded in the Received header lines. Either scrub the original Received line [no explanation provided of how that’s done], or don’t use SMTP for email submission.”

    Is this something I should be concerned about security-wise? Or does this plugin solve this problem somehow? And if not, how should I fix it?

    Thanks!

    • WPBeginner Support says:

      You shouldn’t be concerned about it. Most popular email service providers and their spam filters can check if an email is originating from the IP address it claims to be coming from.

  10. Rob says:

    Thank YOU so much for this!! I’ll keep coming back for more!! :)

  11. Travis says:

    Thanks so much for this tutorial.

    Originally I had this all setup and working fine, but I moved my website and did some other fixes to it, and suddenly mailing stopped working.

    Previously I spent some time trying to set it up and get it to work, but then it “stopped” working randomly.

    Anyways, option #1 really saved me a major headache.

  12. Christine Tabor says:

    I configured, and got the green go to go button… THANKS FOR THE STEP BY STEP…
    (doing this on a client test site)…

    BUT REGARDING GRAVITY FORMS (or any form plug in)… do I also need to change up the notification emails that I’ve used for the Gravity Forms submissions?

    Is it ok for the “from” email I used in the configuration to be different than the gmail used to set i up?

    The issue that started all this was client not getting his Gravity Form notifications.

    SO, before I install on their live site… (which is ecommerce and SSL)… can you reply to this … and should I still use the TSL for the configuration? I wasn’t sure if a certificate on the site made any difference in configuring this.

    Thanks,
    Christine

    • WPBeginner Support says:

      No you don’t need to change notification emails.

      It is OK, but to ensure maximum deliverability you should use the email address that is actually sending the email.

      You should try with SSL first for the Gmail Configuration.

      • Christine says:

        Thanks for reply…little bit more clarification please.

        I set up an email…info@domain.com as a forwarder in cpanel, and I forward to their Verizon email.

        I left the Verizon email in the GF notification list, added the info email, and another alternate email.

        So the info email is the one in Gmail plugin set up that is sending the email…is it ok that it’s a forwarder?

        Also, when I set up the plugin, I used a gmail I had created … CompanyName@gmail.com
        But not using it as the sending email or anywhere else.

        I sent a test and it appears all worked… Should I go back and change to SSL instead of the TSL or leave as is?

        Thanks again…
        Christine

        • WPBeginner Support says:

          Sounds about right. However, if it was up to us we would use the Gmail address as the sender and add the forwarding email address as the Reply-to address.

  13. Tribhuwan Bhatt says:

    Thank You

  14. Tim R says:

    Doesn’t work for me on April 14, 2016.

    Things I do rarely work.

    Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    SMTP ERROR: Failed to connect to server: Network is unreachable (101)
    SMTP connect() failed.
    Mailer Error: SMTP connect() failed.
    Any point in fussing with this ?

    • zse says:

      Hi,
      I have this same error.
      Did you solved this problem?

      Regards ;)

    • Tim R says:

      Here’s a follow up:

      Settings of my web host’s server made this impossible.

      Switched hosts and now it works easy as pie.

      Don’t forget to change settings on gmail account to allow for unregistered apps (a search will discover many instructions to do that so I won’t add it here)

  15. Bclose says:

    Hi ,
    Thanks for this ticket ..i was fighting with my emial provider weblayer and nothing. it worked with your magic touch , one simple note .. by the end of Ouauth when explaining to create a fake local email you forgot to include that we must use MX record and what is is , i search on google and found ALT2.ASPMX.L.GOOGLE.COM, but this last simply thing could be a danwfault for all readers :-)
    Either way thank you..a lot!

  16. Kay says:

    Thank you soooooo much for this! Worked like a charm. The instructions are 100% on point!

  17. Tyler says:

    Anyone get this working with google apps email? I’ve created API credentials. SMTP status is green. But Test email says connection refused. Already set mx to remote on godaddy. Are there any security setting ls in google apps email that have to be configured?

  18. TJ says:

    Nice article, was able to install the plugin and it sent the email from the plugin test email.

    Fails when using Contact Form 7, any recommendations for a contact form plugin that this might work with?

    Thanks

  19. Muhammad says:

    thanks for the nice post.i was thinking to set up this for my site.

  20. Ripul says:

    Interesting, however I am getting this error : “Error: redirect_uri_mismatch”

  21. Rashmirekha Moharana says:

    Hi Syed.

    Thanks a lot for such a wonderful solution. Let me implement and see.

    Kudos to you.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.