Gmail SMTP Plugin for WordPress

Gmail SMTP is an advanced SMTP mailing plugin for WordPress for sending an email via Gmail SMTP server. Unlike most SMTP plugins It uses the OAuth 2.0 protocol to authorize access to the Gmail API instead of password authentication.

gmail smtp wordpress plugin

Gmail SMTP Benefits

1. Gmail SMTP plugin does not store your password. It uses the OAuth 2.0 mechanism for SMTP authentication. It means a more secure login system for users.

2. Gmail SMTP plugin uses PHPMailer – a very popular PHP library used in the core WordPress for sending an email. This is to make sure that users can still get full benefits of the default email functionality.

3. Gmail SMTP plugin takes a big headache away from you because you no longer need to Allow Less Secure Apps on your Gmail account. This is an option that users had to enable in order to fix SMTP connection issue. This issue went viral from December 2014, when Google started imposing OAuth 2.0 authentication to access their apps. This option affects SMTP mailing because applications that perform password authentication to IMAP, POP, or SMTP are considered Less Secure Apps.

As far as I know, this issue still affects almost all the SMTP plugins out there.

How OAuth 2.0 Authorization Works

1. You register a web application in the Google Developers Console.

2. When this application is launched it requests that you give it access to data in your Google account.

3. If you consent, the application receives credentials to access the API.

Installation

You can install the Gmail SMTP plugin in one of the following ways:

Option 1 (Quick & Easy install)

  1. Go to Plugins->Add New from your WordPress admin dashboard
  2. Search for “gmail smtp naa986”
  3. Click Install once you have found it

Option 2 (Manual install)

  1. Download the zip version of the plugin
  2. Go to Plugins->Add New
  3. Click Upload Plugin
  4. Select the zip file on your computer
  5. Install it

Gmail SMTP Configuration

In order to get started with the plugin go to Settings->Gmail SMTP from your admin dashboard.

screenshot of gmail smtp plugin menu

Gmail SMTP Project Creation

1. Go to console.cloud.google.com/apis/dashboard.

2. Login to your Google account which will be used to send an email.

3. Create a new project where your application will be registered.

screenshot showing how to create a new project in the Google Developers Console

It doesn’t have to be “Gmail SMTP Project 1”. You can name it whatever you like. I chose a meaningful name because I have multiple projects in it.

Credentials/App Creation

1. Once the project is created go to Credentials > CREATE CREDENTIALS and select OAuth client ID.

2. In order to create an OAuth client ID, you need to configure the OAuth consent screen first. So click CONFIGURE CONSENT SCREEN.

screenshot showing how to configure the consent screen when creating an OAuth Client ID

3. Choose how you want to configure and register your app. Since I’m not using G Suite I had to choose External.

screenshot showing how to choose a user type in the oauth consent screen of the google developers console

4. Enter a name (e.g. Gmail SMTP) for the OAuth consent screen.

screenshot showing the OAuth consent screen 2 in the google developers console

5. You can configure optional fields such as Authorized domains, Application home page, Application privacy policy link and Application terms of service link (I was able to skip all and click SAVE AND CONTINUE). You do however need to enter an email address under the Developer contact information section.

screenshot showing part 2 of the consent screen 2 in the google developers console

6. Skip the Scopes screen.

screenshot showing the Scopes tab in the OAuth consent screen of the Google cloud console

7. Add a test user if you plan to use this app in test mode (This is not required if you want to publish it).

screenshot showing the Test users tab in the OAuth consent screen of the Google cloud console

8. Keep your app in test mode or publish it. If the Publishing status is set to In production, a warning message (This app isn’t verified) may appear on the consent screen that you can easily skip.

screenshot showing the Summary tab in the OAuth consent screen of the Google cloud console

Now that the OAuth consent screen has been configured you can create an OAuth Client ID.

9. Go to the Credentials tab and select OAuth client ID under CREATE CREDENTIALS.

screenshot showing how to select OAuth client Id under CREATE CREDENTIALS in the google developers console

10. Set the application type to Web application and enter a name for it (e.g. Gmail SMTP App). Copy the Authorized Redirect URL from the settings and paste it into the field here.

screenshot showing how to create a client id by creating a new web app in the google developers console

11. Click Create. This will generate a Client ID and Client Secret for you. Copy and paste them into the settings area of the plugin.

Gmail SMTP Settings Configuration

1. Configure the rest of the settings. It includes,

OAuth Email Address: The email address that you will use for SMTP authentication. This should be the same email used in the Google Developers Console.

From Email Address: The email address which will be used as the From Address when sending an email.

From Name: The name which will be used as the From Name when sending an email.

Type of Encryption: The encryption which will be used when sending an email (either TLS/SSL). By default, it should be set to TLS since SSL has been deprecated since 1998.

SMTP Port: The port which will be used when sending an email. If you choose TLS it should be set to 587. For SSL use port 465 instead.

2. Click Save Changes.

Now that you have configured the settings a Grant Permission button will appear.

screenshot showing how to grant permission from the gmail smtp settings

3. Clicking on it will take you to a consent screen where you will be able to grant this app access to the Gmail API.

allow application screen of google developers console

4. When you click Allow you will get redirected back to the plugin settings. You should see a message like Access Granted Successfully. The SMTP Status should also get set from Not Connected to Connected.

screenshot of gmail smtp settings

That’s it. Gmail SMTP plugin will now be able to take control of all outgoing email from your website.

Test Email

In order to test the email functionality, you can send a test email from the Test Email tab.

Debug option is enabled by default for the test email functionality – which means you would be able to see if the plugin was able to send the email without any error.

screenshot showing how to send a test email from the gmail smtp plugin settings

Troubleshooting

By default, your SMTP port should be configured on 587 (with TLS encryption). If you can’t get it to work then you can try changing it to 465 (with SSL encryption).

If you still can’t get either to work try port 25 with TLS first and then SSL. Please note that most servers don’t support encryption on port 25, which is why port 587 and 465 are the preferred options.

Fresh Authorization / Removing Access From the Application

For some reason, if you ever want to stop using this plugin or do a fresh authorization this option might come in handy.

Revoke Access menu allows you to remove access from a previously authorized application.

screenshot showing the revoke access settings of gmail smtp plugin

First, you need to click on the account settings link. This will take you to a page where you can remove access from the Gmail SMTP application.

screenshot showing how to remove access from an application in the google developers console

Once you have removed access from it, go back to the Remove Access tab in the plugin settings and delete the Access key.

Access key is a token that the plugin received when you first granted your app access to the Gmail API. This token is necessary to communicate with the Gmail API and send an email. In order to avoid any confusion, the plugin does not show it on the settings page.

Once you delete this token the plugin can no longer connect to the Gmail SMTP server or send an email. This means you will need to reauthorize (using the web application link in the settings) before you can start using the plugin again. However, you won’t need to set up everything from scratch as long as the project still exists in your Google Developers Console.

Gmail SMTP Add-ons

Gmail SMTP plugin comes with add-ons that you can use to enhance its functionality on your website.

Reply-To

Reply-To add-on lets you set a reply-to address for all outgoing email messages.

Cc

Cc add-on lets you set a cc recipient for all outgoing email messages.

712 thoughts on “Gmail SMTP Plugin for WordPress”

  1. Followed your instructions but not working. Nothing happens when using the TLS/587 or SSL/465, ther’s just a little box in the bottom left hand corner of the screen that says ‘waiting for easywaste.com.au’, nothing else happens.

    If I change the setting to SSL/25 i at least get the error log appear saying :

    2017-11-28 12:25:13 Connection: opening to ssl://smtp.gmail.com:25, timeout=300, options=array ()
    2017-11-28 12:25:15 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:25 (Network is unreachable) [/home7/japansno/public_html/easywastecom/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php line 298]
    2017-11-28 12:25:15 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
    SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    Server settings are :
    OS: Linux host400.hostmonster.com 3.10.0-614.10.2.lve1.4.50.el6h.x86_64 #1 SMP Mon May 22 17:31:11 EDT 2017 x86_64
    PHP version: 7.0.25
    WordPress version: 4.9
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.24.0, OpenSSL/1.0.0

    Any advice?

    Reply
    • @Simon, Please contact your web host to make sure that port 587 is open and supports TLS encryption.

      Reply
  2. Hi,

    When I use this I get this error:
    2017-11-29 05:19:59 SMTP ERROR: AUTH command failed: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
    SMTP Error: Could not authenticate.
    2017-11-29 05:19:59 CLIENT -> SERVER: QUIT
    2017-11-29 05:19:59 SMTP -> get_lines(): $data is “”
    2017-11-29 05:19:59 SMTP -> get_lines(): $str is “535-5.7.8 Username and Password not accepted. Learn more at”
    2017-11-29 05:19:59 SMTP -> get_lines(): $data is “535-5.7.8 Username and Password not accepted. Learn more at”
    2017-11-29 05:19:59 SMTP -> get_lines(): $str is “535 5.7.8 support.google.com/mail/?p=BadCredentials w5sm1100313pfw.51 – gsmtp”
    2017-11-29 05:19:59 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 support.google.com/mail/?p=BadCredentials w5sm1100313pfw.51 – gsmtp
    2017-11-29 05:19:59 SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 support.google.com/mail/?p=BadCredentials w5sm1100313pfw.51 – gsmtp
    2017-11-29 05:19:59 Connection: closed

    Others have had this error and have not posted a solution. It may come from me having previously used a different smtp plugin.

    I’ve tried revoking and granting permission again. Deleting this plugin and reinstalling it – but I notice that it remembers the deleted settings when its reinstalled.

    Is there a way to really delete it to try and get it to reconfigure.

    Thanks for your help!

    Matt
    OS: Linux webhost.cenet.catholic.edu.au 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64
    PHP version: 5.6.32
    WordPress version: 4.9
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.55.1, OpenSSL/1.0.2m

    Reply
    • @Matt, This issue seems to occur on a few servers. I haven’t been able to find a solution to this. Please do the following:

      1) Follow the steps outlined in the “Fresh Authorization / Removing Access From the Application” section.
      2) Go back to the general settings and click on the “Grant Access” button (it should appear now that you have deleted the access key).
      3) Copy the ful URL shown in the address bar of your browser when you go to the app permission screen.
      4) Send the URL to me by using the contact form on the site.

      Reply
      • Hi,
        Happy weird but that resolved the issue this time!
        I’ve done that a couple of times before with no joy. Clearly this is some undiscovered quantum law that these things don’t work until an admin looks at it 😉
        Thanks heaps for your help
        Matt

        Reply
      • I have this same issue when I change the account password. When I try to follow your directions for “Fresh Authorization / Removing Access From the Application” the app is not listed. This prevents me from setting it up again.

        Reply
  3. Can I use a different domain in the “From Email Address”?

    I’ve configured everything to work, but it is still showing my GMAIL email address when sending out emails. I wanted it to be an email from my domain, such as sales@myshop.com

    Is there any additional configuration for me to set to customize the from-address?

    Reply
    • @Nicky, The plugin does send the “from email address” to Gmail. But Gmail still shows the actual oauth email address because it doesn’t allow email spoofing.

      Reply
      • Got it. If Gmail doesn’t allow email spoofing, the “from email address” is actually redundant then since it would have no effect at all?

        Reply
      • I’m a developer that have a client that uses this plugin. I’m the owner of the api oauth email, but it needs to sent mails from the client’s email adress. What would you suggest we do?

        Reply
        • @Juri, You mean you want the “From Email Address” to be the client’s email when the actual email is actually being sent from the oAuth email address?

          Reply
          • Yes – I own the email that owns the oauth, but the webshop needs to ship mails fra the client’s email adress.

          • Why even have the “From Email Address” field if the emails are sent from the oauth email?

          • @Juri, Gmail doesn’t allow this for security reasons at the moment. The plugin does pass the “From Email Address” specified in the settings to Gmail but it simply ignores it.

  4. Hi can you please help me with this?

    2017-11-30 09:40:01 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    2017-11-30 09:40:04 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Connection refused) [/home/dekoningkeukens/public_html/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php line 298]
    2017-11-30 09:40:04 SMTP ERROR: Failed to connect to server: Connection refused (111)

    OS: Linux cloud.penthionstudio.nl 2.6.32-696.3.2.el6.x86_64 #1 SMP Tue Jun 20 01:26:55 UTC 2017 x86_64
    PHP version: 7.0.26
    WordPress version: 4.8.4
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Disabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.55.1, OpenSSL/1.0.2m

    Reply
    • @Jan-Peter, Please contact your web host to make sure that port 587 is open and supports TLS encryption.

      Reply
      • Hi there… It seems to be the case that TLS is not supported.
        So we tried the SSL with poort 465 but that results in the same error

        Reply
      • Hi, We tried everything but have you any suggestions.. still the same.
        2017-12-01 09:55:05 Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
        2017-12-01 09:55:08 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused) [/home/dekoningkeukens/public_html/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php line 298]
        2017-12-01 09:55:08 SMTP ERROR: Failed to connect to server: Connection refused (111)
        SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

        Reply
  5. Just wanted to say thanks for such a great tutorial. Its perfectly exlained, step by step and you also give support! woww! Thanks again, this was really usefull.

    Reply
    • @Santiago, You’re welcome :).

      Reply
  6. Hi,

    I’ve followed your guide, thanks for this. I’ve got everything working correctly so far, SMTP is connected etc. however when I send a test email I get the following:

    2017-12-04 02:12:21 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    2017-12-04 02:12:21 Connection: opened
    2017-12-04 02:12:21 SMTP -> get_lines(): $data is “”
    2017-12-04 02:12:21 SMTP -> get_lines(): $str is “220 smtp.gmail.com ESMTP c8sm8304525pfm.92 – gsmtp”
    2017-12-04 02:12:21 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP c8sm8304525pfm.92 – gsmtp
    2017-12-04 02:12:21 CLIENT -> SERVER: EHLO mystuffstickers.com
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-STARTTLS”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-STARTTLS”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-12-04 02:12:22 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-12-04 02:12:22 CLIENT -> SERVER: STARTTLS
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “220 2.0.0 Ready to start TLS”
    2017-12-04 02:12:22 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
    2017-12-04 02:12:22 CLIENT -> SERVER: EHLO mystuffstickers.com
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-12-04 02:12:22 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-12-04 02:12:22 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-12-04 02:12:22 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2404:8280:a111:101::6c]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-12-04 02:12:22 Auth method requested: XOAUTH2
    2017-12-04 02:12:22 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
    2017-12-04 02:12:24 CLIENT -> SERVER: AUTH XOAUTH2 dXNlcj1pbmZvQG15c3R1ZmZzdGlja2Vycy5jb20BYXV0aD1CZWFyZXIgAQE=
    2017-12-04 02:12:25 SMTP -> get_lines(): $data is “”
    2017-12-04 02:12:25 SMTP -> get_lines(): $str is “334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==”
    2017-12-04 02:12:25 SERVER -> CLIENT: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
    2017-12-04 02:12:25 SMTP ERROR: AUTH command failed: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
    SMTP Error: Could not authenticate.
    2017-12-04 02:12:25 CLIENT -> SERVER: QUIT
    2017-12-04 02:12:25 SMTP -> get_lines(): $data is “”
    2017-12-04 02:12:25 SMTP -> get_lines(): $str is “535-5.7.8 Username and Password not accepted. Learn more at”
    2017-12-04 02:12:25 SMTP -> get_lines(): $data is “535-5.7.8 Username and Password not accepted. Learn more at”
    2017-12-04 02:12:25 SMTP -> get_lines(): $str is “535 5.7.8 support.google.com/mail/?p=BadCredentials c8sm8304525pfm.92 – gsmtp”
    2017-12-04 02:12:25 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 support.google.com/mail/?p=BadCredentials c8sm8304525pfm.92 – gsmtp
    2017-12-04 02:12:25 SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 support.google.com/mail/?p=BadCredentials c8sm8304525pfm.92 – gsmtp
    2017-12-04 02:12:25 Connection: closed
    SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    I take it I’ve got credential errors but I’ve copied and pasted them exactly several times. Any ideas?

    Reply
    • @Bennbil, Please follow the steps outlined in the “Fresh Authorization / Removing Access From the Application” section and see how it goes.

      Reply
    • Works now. Thank you very much!

      Reply
  7. My problem is below
    Fatal error: Uncaught InvalidArgumentException: Invalid token format in
    Somebody can help me
    Thank you

    Reply
    • I am also receiving this error. I have used this plugin many times with great success and on sites on this same server where it is running well. I am not sure why I am getting this particular error at the moment, but any help would be greatly appreciated.

      Notice: Undefined index: refresh_token in /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugins/gmail-smtp/main.php on line 685
      2017-12-06 19:16:59 Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
      2017-12-06 19:16:59 Connection: opened
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “220 smtp.gmail.com ESMTP i133sm6668274itf.1 – gsmtp”
      2017-12-06 19:16:59 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP i133sm6668274itf.1 – gsmtp
      2017-12-06 19:16:59 CLIENT -> SERVER: EHLO abcxyz.com
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]”
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “250-SIZE 35882577”
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]250-SIZE 35882577”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “250-8BITMIME”
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]250-SIZE 35882577250-8BITMIME”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “250-PIPELINING”
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “250-CHUNKING”
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “250 SMTPUTF8”
      2017-12-06 19:16:59 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2607:f1c0:855:cc00::26:b2bb]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
      2017-12-06 19:16:59 Auth method requested: XOAUTH2
      2017-12-06 19:16:59 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
      2017-12-06 19:16:59 CLIENT -> SERVER: QUIT
      2017-12-06 19:16:59 SMTP -> get_lines(): $data is “”
      2017-12-06 19:16:59 SMTP -> get_lines(): $str is “221 2.0.0 closing connection i133sm6668274itf.1 – gsmtp”
      2017-12-06 19:16:59 SERVER -> CLIENT: 221 2.0.0 closing connection i133sm6668274itf.1 – gsmtp
      2017-12-06 19:16:59 Connection: closed

      Fatal error: Uncaught InvalidArgumentException: Invalid token format in /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php:434 Stack trace: #0 /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugins/gmail-smtp/class.phpmaileroauthgoogle.php(139): Google_Client->setAccessToken(Array) #1 /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php(475): GmailXOAuth2->getOauth64() #2 /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugins/gmail-smtp/class.phpmaileroauth.php(152): SMTP->authenticate(”, ”, ‘XOAUTH2’, ”, ”, Object(GmailXOAuth2)) #3 /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1542): PHPMailerOAuth->smtpConnect(Array) #4 /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1337): PHPMailer->smtpSend(‘Date: Wed, 6 De…’, ‘tn’) #5 /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugi in /var/www/vhosts/abcxyz.com/httpdocs/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php on line 434

      Reply
  8. I too am getting this error:

    2017-12-05 13:40:13 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-12-05 13:40:13 Connection: opened
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “220 smtp.gmail.com ESMTP b67sm455627pfm.19 – gsmtp”
    2017-12-05 13:40:13 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP b67sm455627pfm.19 – gsmtp
    2017-12-05 13:40:13 CLIENT -> SERVER: EHLO mindnlife.com
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [198.54.114.93]”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-STARTTLS”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-STARTTLS”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-12-05 13:40:13 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-12-05 13:40:13 CLIENT -> SERVER: STARTTLS
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “220 2.0.0 Ready to start TLS”
    2017-12-05 13:40:13 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
    2017-12-05 13:40:13 CLIENT -> SERVER: EHLO mindnlife.com
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [198.54.114.93]”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-12-05 13:40:13 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-12-05 13:40:13 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-12-05 13:40:13 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [198.54.114.93]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-12-05 13:40:13 Auth method requested: XOAUTH2
    2017-12-05 13:40:13 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
    2017-12-05 13:40:15 CLIENT -> SERVER: AUTH XOAUTH2 dXNlcj1kcnphaWRpQG1pbmRubGlmZS5jb20BYXV0aD1CZWFyZXIgeWEyOS5HbHNaQlNibG5EMWhPM2ozMUNNNjExZjhZYUZheFhZRWJnVXhSQ3NOdHRvdUtSbmF4eVYyRHEwOTlWSXIyU0ExeVp1akY2bnd5QVBQMFFsVXFsM1hFVjNWQ29IaXFRUmo2MW8tanowSS1OUDNkcU05UWVDNDF0UDFxQ1dnAQE=
    2017-12-05 13:40:15 SMTP -> get_lines(): $data is “”
    2017-12-05 13:40:15 SMTP -> get_lines(): $str is “334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==”
    2017-12-05 13:40:15 SERVER -> CLIENT: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
    2017-12-05 13:40:15 SMTP ERROR: AUTH command failed: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
    SMTP Error: Could not authenticate.
    2017-12-05 13:40:15 CLIENT -> SERVER: QUIT
    2017-12-05 13:40:15 SMTP -> get_lines(): $data is “”
    2017-12-05 13:40:15 SMTP -> get_lines(): $str is “535-5.7.8 Username and Password not accepted. Learn more at”
    2017-12-05 13:40:15 SMTP -> get_lines(): $data is “535-5.7.8 Username and Password not accepted. Learn more at”
    2017-12-05 13:40:15 SMTP -> get_lines(): $str is “535 5.7.8 support.google.com/mail/?p=BadCredentials b67sm455627pfm.19 – gsmtp”
    2017-12-05 13:40:15 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 support.google.com/mail/?p=BadCredentials b67sm455627pfm.19 – gsmtp
    2017-12-05 13:40:15 SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 support.google.com/mail/?p=BadCredentials b67sm455627pfm.19 – gsmtp
    2017-12-05 13:40:15 Connection: closed
    SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    I’ve been through the Fresh Authorisation /Revoke Access several times also. I even completely deleted the entire project and plugin, then reinstalled and recreated etc. Cannot figure out what the problem could be – please help!

    Reply
  9. I have just upgraded to V 1.1.6 and it is reporting that my PHP version is less than V 5.6, my cpanel shows the version to be :
    cpsrvd 11.68.0.19
    Database client version: libmysql – 5.1.73
    PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
    PHP version: 5.6.30

    This is what the plugin shows:
    OS: Linux 070615.vps-10.com 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64
    PHP version: 5.4.23
    WordPress version: 4.8.4
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.24.0, OpenSSL/1.0.1e

    It will send a test email but is reporting the error in the WP dashboard.

    Reply
  10. I have just finished the set up but when I press the “grant permission button” I got a message saying “google hasn’t verified this app” then I had to type “continue” and press “next”.

    Now, I am left hanging with no page loading, it just seems to freeze and nothing comes up no matter how many times I press the “grant permission”, it goes to the same white page with no text.

    The app status is staying at “not connected”.

    HELP please!!!

    Reply
  11. I installed the plugin and it doesn’t send anything. I have a green connected status indicator. The test email log shows no errors. I tried both TLS and SSL methods. I checked outbound firewall, nothing blocking. Any help available on this?

    2017-12-11 03:58:59 Auth method requested: XOAUTH2
    2017-12-11 03:58:59 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
    2017-12-11 03:58:59 CLIENT -> SERVER: QUIT
    2017-12-11 03:58:59 SMTP -> get_lines(): $data is “”
    2017-12-11 03:58:59 SMTP -> get_lines(): $str is “221 2.0.0 closing connection s4sm3317862ita.12 – gsmtp”
    2017-12-11 03:58:59 SERVER -> CLIENT: 221 2.0.0 closing connection s4sm3317862ita.12 – gsmtp
    2017-12-11 03:58:59 Connection: closed

    OS: Linux ip-172-31-1-10 4.4.0-1038-aws #47-Ubuntu SMP Thu Sep 28 20:05:35 UTC 2017 x86_64
    PHP version: 7.0.22-0ubuntu0.16.04.1
    WordPress version: 4.9.1
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.47.0, OpenSSL/1.0.2g

    Reply
  12. Hi,

    I have a strange problem on the website of my client.
    I have setup GMAIL SMTP following all the steps, it works for a few days and then without any reason it stops working. When it stops working I send a test email that gives no error whatsoever, apart from the fact that the actual message does not get delivered.
    Every time this happens I just revoke access on to GMAIL SMTP and delete access key. After I just regrant permissions on the General tab with exactly the same ID and secret, and it starts working again for a couple of days and stops working again.

    Any clues on why this is happening?

    Reply
    • I too seem to be having this problem as well. Revoke-ReGrant allows things to work again, execpt the test email does not work. But after “restarting” its ok for an unknown length of time.

      Reply
  13. Hello

    I’ve set plugin has explained in documentation but when I try to send a test email I’ve those logs :

    2017-12-12 19:37:48 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    2017-12-12 19:37:48 Connection: opened
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “220 smtp.gmail.com ESMTP j125sm253000wmd.24 – gsmtp”
    2017-12-12 19:37:48 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP j125sm253000wmd.24 – gsmtp
    2017-12-12 19:37:48 CLIENT -> SERVER: EHLO hellomybot.io
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [51.254.212.74]”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-STARTTLS”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-STARTTLS”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-12-12 19:37:48 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-12-12 19:37:48 CLIENT -> SERVER: STARTTLS
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “220 2.0.0 Ready to start TLS”
    2017-12-12 19:37:48 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
    2017-12-12 19:37:48 CLIENT -> SERVER: EHLO hellomybot.io
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [51.254.212.74]”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-12-12 19:37:48 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-12-12 19:37:48 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-12-12 19:37:48 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [51.254.212.74]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-12-12 19:37:48 Auth method requested: XOAUTH2
    2017-12-12 19:37:48 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH

    Reply
    • I’ve found my issue. It was because php5-curl not installed. Sorry !

      Reply
  14. I fail to run the plugin on WP Multisite 4.9.1 (PHP 7.1, cUrl, allow_fopen=disabled).

    The WPMU is used for different languages.
    It does work for the main site, but not on the second on subdomain site.

    I get the refresh-token error as described above.

    Before debugging – what is the *complete* setting for WP multisite with Gmail-SMTP.
    In particular, what is required for the 2nd, 3rd, … sites?

    Reply
  15. Hi and thanks for this great guide!
    On my website I have several forms and people put in their emails. We get the mail from the site and it also shows the email entered and when we click reply it still shows the email from the form, however the reply is not send to the email, but the gmail. How to fix this?

    Reply
  16. Hi My name is Neha,

    I have this error every time I send a test email:

    Fatal error: Uncaught exception ‘InvalidArgumentException’ with message ‘Invalid token format’ in /home4/neha/public_html/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php:434 Stack trace: #0 /home4/neha/public_html/wp-content/plugins/gmail-smtp/class.phpmaileroauthgoogle.php(139): Google_Client->setAccessToken(‘{“error”:”inval…’) #1 /home4/neha/public_html/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php(475): GmailXOAuth2->getOauth64() #2 /home4/neha/public_html/wp-content/plugins/gmail-smtp/class.phpmaileroauth.php(153): SMTP->authenticate(”, ”, ‘XOAUTH2’, ”, ”, Object(GmailXOAuth2)) #3 /home4/neha/public_html/wp-content/plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1542): PHPMailerOAuth->smtpConnect(Array) #4 /home4/neha/public_html/wp-content/plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1337): PHPMailer->smtpSend(‘Date: Fri, 15 D…’, ‘jhvgvn’) #5 /home4/neha/public_html/wp-content/plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1215): PHPMailer->postSend() #6 /home4/neha/ in /home4/neha/public_html/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php on line 434

    I have no experience coding and every time I ask someone they give me an explanation I don’t understand. Do you know how to fix this??

    Reply
    • hello,
      I have the same problem; until a few days ago it worked fine

      [19-Dec-2017 10:15:25 UTC] PHP Fatal error: Uncaught exception ‘InvalidArgumentException’ with message ‘Invalid token format’ in ..plugins/gmail-smtp/google-api-php-client/src/Google/Client.php:434
      Stack trace:
      #0 …plugins/gmail-smtp/class.phpmaileroauthgoogle.php(139): Google_Client->setAccessToken(‘{“error”:”inval…’)
      #1 …plugins/gmail-smtp/PHPMailer/class.smtp.php(475): GmailXOAuth2->getOauth64()
      #2 …plugins/gmail-smtp/class.phpmaileroauth.php(153): SMTP->authenticate(”, ”, ‘XOAUTH2’, ”, ”, Object(GmailXOAuth2))
      #3 …plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1542): PHPMailerOAuth->smtpConnect(Array)
      #4 …plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1337): PHPMailer->smtpSend(‘Date: Tue, 19 D…’, ‘testn’)
      #5 …plugins/gmail-smtp/PHPMailer/class.phpmailer. in …plugins/gmail-smtp/google-api-php-client/src/Google/Client.php on line 434

      Reply
  17. The plugin only works for about a day and then stops. It will work again after a refresh, either keeping the same key or generating a new one. Self hosted on a Mac OSX server, everthing up to date. Any suggestions?

    2017-12-28 13:53:52 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    2017-12-28 13:53:52 Connection: opened
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “220 smtp.gmail.com ESMTP s187sm12305201wmf.16 – gsmtp”
    2017-12-28 13:53:52 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP s187sm12305201wmf.16 – gsmtp
    2017-12-28 13:53:52 CLIENT -> SERVER: EHLO bazteksolutions.com
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [99.181.12.36]”
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “250-STARTTLS”
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-STARTTLS”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-12-28 13:53:52 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-12-28 13:53:52 CLIENT -> SERVER: STARTTLS
    2017-12-28 13:53:52 SMTP -> get_lines(): $data is “”
    2017-12-28 13:53:52 SMTP -> get_lines(): $str is “220 2.0.0 Ready to start TLS”
    2017-12-28 13:53:52 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
    2017-12-28 13:53:53 CLIENT -> SERVER: EHLO bazteksolutions.com
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “250-smtp.gmail.com at your service, [99.181.12.36]”
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “250-SIZE 35882577”
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “250-8BITMIME”
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “250-ENHANCEDSTATUSCODES”
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “250-PIPELINING”
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “250-CHUNKING”
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “250 SMTPUTF8”
    2017-12-28 13:53:53 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [99.181.12.36]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-12-28 13:53:53 Auth method requested: XOAUTH2
    2017-12-28 13:53:53 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
    2017-12-28 13:53:53 CLIENT -> SERVER: QUIT
    2017-12-28 13:53:53 SMTP -> get_lines(): $data is “”
    2017-12-28 13:53:53 SMTP -> get_lines(): $str is “221 2.0.0 closing connection s187sm12305201wmf.16 – gsmtp”
    2017-12-28 13:53:53 SERVER -> CLIENT: 221 2.0.0 closing connection s187sm12305201wmf.16 – gsmtp
    2017-12-28 13:53:53 Connection: closed

    Reply
  18. ” Could not instantiate mail function. ”
    How can we solve the above error…..

    Please Help us

    Reply
  19. Error! Nonce Security Check Failed! please save the settings again.

    Reply
  20. I am unable to send an email from the ‘test email’ screen. No error message is sent from the plugin itself. The following log extract is from my wordpress site error log:-

    [03-Jan-2018 18:20:08 UTC] PHP Notice: Undefined index: refresh_token in /home4/xxxxxxxxx/public_html/xxxxxxxxxxx/wp-content/plugins/gmail-smtp/main.php on line 685

    This is the problem line of code in main.php on line 685:
    //Obtained By running get_oauth_token.php after setting up APP in Google Developer Console.
    //Set Redirect URI in Developer Console as [https/http]:////get_oauth_token.php
    // eg: localhost/phpmail/get_oauth_token.php
    $phpmailer->oauthRefreshToken = $gmail_token[‘refresh_token’];

    Server info:
    OS: Linux gator3312.hostgator.com 3.12.74-216.ELK6.x86_64 #1 SMP Wed Jun 28 20:33:54 CDT 2017 x86_64
    PHP version: 5.6.30
    WordPress version: 4.9.1
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.19.7, NSS/3.27.1

    The problem appears to me to be coming from the Google Console setup, however i have checked and rechecked this for accuracy.

    Can you suggest avenues for investigation? Thank-you.

    Reply
    • I’ve managed to fix the problem. I used the google cloud site to set up instead of the google developer site.

      I commend you on your support site. Previous posts have been very helpful.

      All the best. Ian

      Reply

Leave a Comment