How To Send Emails in WordPress using Gmail SMTP

October 27th, 2015 - Posted by Steve Marks to PHP, Software, Web Development.

The majority of the time we will send emails from enquiry forms using the servers’ built-in mail functionality. This means using the PHP mail() function, or letting WordPress use the mail() function behind the scenes. 99 percent of the time this works fine, however we do sometimes come across scenarios where either:

  • Emails get blocked by spam filters
  • The server IP address gets blacklisted
  • It’s mission critical that an email gets sent successfully

In the above scenarios we don’t use the default server functionality, but instead route emails through an SMTP server. To assist us with this on WordPress sites we would (note the past tense) use the plugin WP Mail SMTP.

Whilst having to do this recently, the SMTP server we would be using was a Gmail account. Although we had the correct SMTP details (host, port, and login credentials) it was still complaining about not being able to authenticate without any further explanation, even though I was knew that the details entered were 100% correct.

The Solution

After a bit of research it turns out that as of a few months ago, you now need to use OAUTH2 authentication in order to send emails using the Gmail SMTP service.

Fortunately I came across a cracking little plugin called Postman SMTP Mailer/Email Log. After installing the plugin, you just run through a quick wizard where it prefills most of the information for you, do the OAUTH authentication bit and then voila… emails start sending.

I am so grateful that this plugin exists, otherwise I think it could have been a few days work to get this working successfully.

So, if you’re looking to send emails via WordPress using Gmail SMTP details, install the plugin mentioned above you’ll be up and running in no time.

This entry was posted on Tuesday, October 27th, 2015 at 11:40 pm by +Steve Marks and is filed under PHP, Software, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first