WPForms Blog

WordPress Tutorials, Tips, and Resources to Help Grow Your Business

Securely Send WordPress Emails with Gmail SMTP

How to Securely Send WordPress Emails Using Gmail SMTP

by Shahzad Saeed on Mar 27, 2017

Looking for a secure SMTP plugin that helps you receive email notifications from your WordPress contact forms? You can use the Gmail SMTP plugin to send WordPress email notifications to your Gmail account, while keeping your login credentials safe. In this post, we’ll show you how to set up Gmail SMTP for sending WordPress emails.

Why You’re Not Receiving Notifications

By default, WordPress uses the PHP mail function to send emails generated by WordPress or any contact plugin like WPForms.  The most common reason for not getting emails is that your WordPress hosting server is not configured to use PHP mail function.

You can fix this by using SMTP instead of the PHP mail function. SMTP (Simple Mail Transfer Protocol) is the industry standard for sending emails reliably.

Why Use the Gmail SMTP Plugin?

The main benefit of using the Gmail SMTP plugin is that it lets you send WordPress emails securely using your Gmail account without you having to enable less secure apps in your account.

In addition, unlike other SMTP plugins, you won’t need to enter your Gmail username and password in your WordPress dashboard where other site users can see them. By using this method, you’ll keep your WordPress site secure.

Let’s take a look at how to set up Gmail SMTP for sending WordPress emails.

Step 1: Install the Gmail SMTP Plugin

The first thing you need to do is to install and activate the Gmail SMTP plugin. You can see this guide on how to install a WordPress plugin for step-by-step instructions.

Step 2: Create a Web Application

Upon activation, you’ll need to visit the Settings » Gmail SMTP page to configure the plugin settings. You’ll now be asked to create a new Gmail web application and enter the details in the settings page.

Gmail SMTP settings

To create an application, go to this page and sign in to your Google account. You can choose to subscribe to the newsletter if you wish. You’ll need to agree to the terms of conditions by selecting the Yes option and then, click Agree and continue.

register application gmail smtp

Then, click Go to credentials.

Click go to credentials

In the next page, you’ll be prompted to determine the credentials you need. Select Gmail API from the dropdown menu.

In the field Where will you be calling the API from?, select Web server. In the radio button below, select user data, then click the button What credentials do I need?

add credentials details

Now you need to enter a name for OAuth client. The name is just for your reference, so you can enter any name you like.

Under Authorized JavaScript origins, enter your website URL.

Now go back to your Gmail SMTP settings page in your WordPress dashboard and copy Authorized Redirect URI. Insert it into Authorized redirect URIs in your Google Developers Console page. Then, click Create client ID.

create client id

In the add credentials step, you’ll be shown your email address and will be asked to specify a preferred product name. Then, click Continue.

oauth client id

You’ve now successfully created the web application. Then, click I’ll do this later.

Step 3: Configure the Gmail SMTP Plugin

In the Credentials page, you can now see the details of the web application you just created. To view Client ID and Client Secret, click the edit icon.

click edit

Now copy Client ID and Secret and insert it into the Gmail SMTP settings page.

To enter other details, just follow the instructions below.

  • OAuth Email Address: Enter the email address you used to create the web application.
  • From Email Address: Use the same email address you used in the above field. Bear in mind that you’ll need to use the same email in the Send From setting in your form notifications.
  • From Name: Enter the from name you would like to display in your email.
  • Type of Encryption: Select TLS from the dropdown menu.
  • SMTP Port: 587
  • You may disable the SSL certificate verification by selecting the checkbox.

gmail smtp set up

Then, select Save Changes.

Now scroll down the settings page. Just below the Save Changes button, you’ll now see a Grant Permission button. Click on it.

You’ll now be redirected to a page where you’ll be asked to allow the web application you just created to read, send, delete and manage emails. Click Allow.

agree app

Now go back to the plugin settings page. You can now see the SMTP status as connected.

smtp status

Step 4: Send a Test Email

Now that we’ve configured the plugin, let’s send a test email and check if you’re receiving it in your Gmail inbox.

To send a test email, click the Test Email tab, specify the To, Subject and Message fields. Click the Send Email button.

test email gmail smtp

If everything was done right, you’ll now see the test email in your Gmail inbox.

That’s it! You’ve successfully configured SMTP on your WordPress site. You’ll now start getting notifications from your WordPress forms.

There are lots of different ways to configure SMTP on your WordPress site to get the form notifications. You can take a look at a few more ways to configure SMTP on your site.

What are you waiting for? Get started with the most powerful WordPress forms plugin today.

If you like this article, then please follow us on Facebook and Twitter for more free WordPress tutorials.

Comments

  1. Awww this is what I got:

    “Error: invalid_scope

    You don’t have permission to access some scopes. Your project is trying to access scopes that need to go through the verification process. {invalid = [https://mail.google.com/]} If you need to use one of these scopes, submit a verification request.

    Learn more

    That’s all we know.”

    Really need to get this up and going. Got any ideas?

    1. Hi Michael,

      Sorry for the trouble! If you’re seeing this in your WordPress admin panels, I’d suggest contacting your hosting provider to ask them to reset file permissions. I’d also suggest running back through this tutorial — this may be a bit time-consuming, but it’s possible something got skipped along the way.

      If you give both of those a shot and still encounter this error, could you contact us in support? That way we collect more details and help you troubleshoot.

      Thanks! 🙂

  2. I have used the plugin and the test email worked but I don’t know how to get the plugin on the website so people can start emailing me. Any help would be great!

  3. I really appreciate the detailed instructions. However, the test email didn’t work at the end. Error showing as:

    2017-08-30 23:05:08 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( ‘ssl’ => array ( ‘verify_peer’ => false, ‘verify_peer_name’ => false, ‘allow_self_signed’ => true, ),)
    2017-08-30 23:05:10 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Network is unreachable)
    2017-08-30 23:05:10 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    Does anyone know why this is?

    Many thanks

    1. Hi Colin,

      Usually when we see a ‘stream_socket_client’ error it’s because your site’s hosting provider is blocking the SMTP, so the SMTP isn’t able to complete its connection. The best next step is to contact the company that hosts your site and ask if they could check for anything blocking SMTPs, and specifically to check port 587 (sometimes hosts will block certain ports by default).

      I hope that helps! If you have any other questions about this, please get in touch 🙂

  4. I’ve followed all the instructions. At the point where I’ve clicked ‘Grant Permission’, instead of being redirected to the page where WPForms can read, access and delete emails (as described), I was redirected to accounts.google.com with a warning that “This app isn’t verified”.
    Can you advise on how I should proceed?

    1. Hi Nat and Dariusz,

      I’m sorry to hear this isn’t working properly for you, and I’ll look into any changes made to this plugin or the Gmail API to see what might be going on.

      For now, the fastest solution will likely be to try a different SMTP option.

      When I’ve had a chance to do some testing, I’ll reply back here. Sorry for the trouble, and thanks for your patience 🙂

      1. Hi Nat and Dariusz,

        Ok, I was able to test this out — I replicated what you described, and was also able to make it work. Here’s what I did:
        – On the ‘This app isn’t verified’ screen from Google, I clicked ‘Advanced’ (screenshot here)
        – Clicking Advanced opened more text, and I could click a link to proceed (screenshot). It says ‘unsafe’, but only because we haven’t had a chance to grant permission yet — so no worries on that
        – Now, I get to see the permissions screen (screenshot)

        I’m sorry for the trouble with that! Google must have added this extra layer of warnings recently, as Dariusz mentioned. I’ll make a note for us to test this a bit more and update the documentation accordingly.

        Thanks for letting us know about this, and I hope that helps! 🙂

  5. I am receiving this error when trying to send a test email. It is rather long, but any help is appreciated.

    2017-09-07 18:52:33 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( ‘ssl’ => array ( ‘verify_peer’ => false, ‘verify_peer_name’ => false, ‘allow_self_signed’ => true, ),)
    2017-09-07 18:52:33 Connection: opened
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “220 smtp.gmail.com ESMTP 131sm152107ioe.74 – gsmtp”
    2017-09-07 18:52:33 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 131sm152107ioe.74 – gsmtp
    2017-09-07 18:52:33 CLIENT -> SERVER: EHLO zurahealth.com
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [35.184.204.182]”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-STARTTLS”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-STARTTLS”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-09-07 18:52:33 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-09-07 18:52:33 CLIENT -> SERVER: STARTTLS
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “220 2.0.0 Ready to start TLS”
    2017-09-07 18:52:33 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
    2017-09-07 18:52:33 CLIENT -> SERVER: EHLO zurahealth.com
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [35.184.204.182]”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-09-07 18:52:33 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [35.184.204.182]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-09-07 18:52:33 Auth method requested: XOAUTH2
    2017-09-07 18:52:33 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
    2017-09-07 18:52:33 CLIENT -> SERVER: QUIT
    2017-09-07 18:52:33 SMTP -> get_lines(): $data is “”
    2017-09-07 18:52:33 SMTP -> get_lines(): $str is “221 2.0.0 closing connection 131sm152107ioe.74 – gsmtp”
    2017-09-07 18:52:33 SERVER -> CLIENT: 221 2.0.0 closing connection 131sm152107ioe.74 – gsmtp
    2017-09-07 18:52:33 Connection: closed

    1. Hi Jessica,

      Thanks for sharing that log 🙂 However, I don’t see any clear reason there for the issue you described. When you have a chance, would you please submit a ticket so we can collect some extra details?

      Thanks! 🙂

  6. Thanks for the clearly laid out instructions … BUT … when I hit the save changes button, the ‘grant permissions’ button did not appear. any idea why?

    1. Hi Gary,

      I’d suggest trying to clear any caches (for your browser and, if you have them, in your site) and refresh the page.

      If this button still doesn’t appear after trying this, could you please let us know in support (here are links for our paid plugin support and Lite support)?

      Thanks! 🙂

  7. Hello,

    Thank you very much for the information..but when I click on the allow button it redircted me to a page :
    This page isn’t working

    mydomainname.com is currently unable to handle this request.
    HTTP ERROR 500

    and when I open the SMTP setting page the
    SMTP Status =Not Connected

    1. Hi M,

      Sorry for the trouble! A 500 error means something went wrong on the server, so the best next step is to contact your hosting provider to find out more details and see if they can help you to fix it. They should be able to check error logs for your site and get more specific details for you.

      I hope that helps! If you have any other questions, please feel welcome to contact our support — here for a paid licenses or here for our free version 🙂

  8. I am getting this error:

    2017-11-20 15:49:51 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    2017-11-20 15:49:53 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Connection refused) [/home/content/a2pewpnaspod04_data05/82/41380082/html/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php line 299]
    2017-11-20 15:49:53 SMTP ERROR: Failed to connect to server: Connection refused (111)
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    Any ideas?

    1. Hi Luke,

      I’m sorry for the trouble with that! Most often when we see a stream_socket_client() error it’s because something on your site’s server is blocking the SMTP from working — so the best next step is to contact your site’s hosting provider and ask about that.

      If you give that a try and still see an issue, or have any other questions, please let us know! We provide support to our paid version users here and to our Lite version users here 🙂

  9. This isn’t working for us. It says we are connected but the test email shows the following issues:

    2017-12-01 17:15:16 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    2017-12-01 17:15:18 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Connection refused) [/home/jmort/public_html/wordpress/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php line 298]
    2017-12-01 17:15:18 SMTP ERROR: Failed to connect to server: Connection refused (111)
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    1. Hi Brett,

      Sorry for the trouble with that! Generally when we see a stream_socket_client() error like this, it’s because your hosting provider is blocking the port needed by the SMTP — in this case, Port 587.

      The best next step is to contact your site’s hosting provider and ask about this. Just a heads up, it’s likely that your host will ask if everything else is configured correctly so it may be worth checking back through this tutorial on more time to be sure everything is in place before reaching out.

      If you have any other questions after giving that a shot, could you please let us know? We have support available for our paid version here and for WPForms Lite here, and we’d be happy to help 🙂

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 privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.