Using a SMTP server to send Gravity Forms notifications

8 0

Gravity Forms, like almost all other WordPress plugins, uses the WordPress core function wp_mail() to send all the emails. So the process of sending the email is not controlled by Gravity Forms, is WordPress really who is going to ask your server to send the emails.

Web hosting companies don’t expect you to use their servers to send a large number of emails from your site, specially if you’re in a shared hosting plan, they mainly provide you the email service to be used by you as “human”. Also due to the limitations and restrictions that some hosting companies puts on their SMTP servers to prevent abuse and spam, it’s not a good idea to use the SMTP provided by your hosting company, you can easily be considered a spammer by your hosting just because you’re sending large amounts of emails. So if you’re receiving many form entries per day it’s easy to have email delivery problems due to the mentioned limitations and restrictions set in the server.

So in this little guide we’re going to use a method that will make WordPress to send Gravity Forms notifications, and any other email sent using wp_mail() core function, through a third-party SMTP server instead of using your web hosting resources.

Third-party services and SMTP servers that you can try

All the services below are offering SMTP servers to send transactional emails:

Things that you need to follow this tutorial:

  • An account for any of the third-party services mentioned in this article.
  • Username, password, hostname, port, and encryption type of the SMTP server that you want to configure.
  • A plugin to put this details, in this article we’re going to use SAR Friendly SMTP (created by me) that you can install from your WordPress dashboard. Don’t forget to give it a good rating if you find it useful.

As an example I’ll show how to use SAR Friendly SMTP with the SMTP server provided by Sendgrid and with Gmail (the same applies for Google Apps accounts), although using Gmail SMTP server is not always a good choice, but I’ll explain how to configure it because it’s very popular. Configuring the plugin using any other service is pretty the same, you just need to use the appropriate SMTP server details provided by the third-party service of your choice.


Sengrid SMTP settings

Sengrid SMTP settings

SendGrid is a well known transactional email service, that means you can use their API or their SMTP server for delivering emails. They offer a free account (no credit card required) that allows you to send up to 12.000 emails per month and cheap prices if you need to send more.

So we can start by using their free account that works pretty fine and provides us with a reliable SMTP server and also additional information that will be very useful when peforming troubleshooting.

These are the settings for using Sendgrid SMTP server:

  • Username: Enter your Sengrid username here.
  • Password: Your Sengrid password here.
  • SMTP Server:  smtp.sendgrid.com
  • Port: Enter value 465
  • Encryption: Set it to SSL

And we’re done with the server details. You can save changes and go to Tools -> Send Email Test to make a sending test.

By going to your SendGrid account and clicking in the Activity menu option at the left side of the screen you can see a log of the emails handled by SendGrid and their status. If all goes ok you should see Processed and Delivered for each email sent to the SendGrid SMTP server.

In addition to the above setup using SAR Friendly SMTP plugin SendGrid also has an official plugin for WP that allows you to send the emails using their API, but I don’t have tested it so I can’t tell you how it works. What I use on my sites is the above setup with SAR Friendly SMTP and never had a problem.

USING Gmail SMTP server

This is a common setup but it’s not recommended for the following reasons:

  1. Google only allows you to send emails using your account email address in the FROM header. That means if your Gmail account is [email protected] that will be used always as from address. No matter what you put in your notifications or in the SMTP settings, Google will replace any address in the from field with your account address.
  2. Gmail has from long time ago a known issue regarding to Reply-To field in the email header, causing to ignore the Reply-To field in the email if your FROM field has any email configured in your Gmail account, and to make it more weird, sometimes this is only an intermittent issue. (If you search in Google you’ll find a lot of people talking about it).We can’t control what Gmail does, but this can be sorted out by simply using in the FROM address field an email different from the ones configured in your Settings -> Accounts (at your Gmail email account). But as we have mentioned above, you can’t do this using the Gmail SMTP server.
  3. To prevent spammers from using their servers, Google applies additional restrictions to the number of emails you can send per day and also to the number of recipients addresses you can include in each email.

So as you can see it’s better to avoid the use of Gmail SMTP server.

If you think you’ll be ok using Gmail SMTP server, these are the details you need to configure in SAR Friendly SMTP settings page:

  • Username: Put your full email address as username, i.e. [email protected]
  • Password: Just put the password for your Gmail account 🙂
  • SMTP Server: For Gmail/Google Apps put smtp.gmail.com
  • Port: Enter value 587
  • Encryption: Set it to TLS

And we’re done again with the server details. You can save changes and go to Tools -> Send Email Test to make a sending test.

Additional tips to improve your email deliverability and reputation

Below you can find some tips that will help you to avoid to be considered a spammer by most email providers.

  • Configure the SPF record in your domain to validate the source of your emails. Some the above services will force you to do it before using them, but even for the ones that don’t force you to do it, it’s a good practice and recommended.
  • Don’t use the email address of your users in your from address in the Grativy Forms notifications setting. That is what spammers do! Use always an email that belongs to your site domain. You can use the Reply To setting to store your user’s email address.
  • Don’t use an email subject with ALL CAPITAL LETTERS. Again is something that spammers do and spam filters can take this into account.
  • Don’t send unsolicited emails. Always ask your users for permission to receive emails from you (e.g. by adding a checkbox to your form and a privacy policy to your site). If you use the emails provided by your users without their permission or for different use cases than the ones described in your privacy policy, your users are going to mark your emails as spam, and that is going to hurt your domain reputation. Once a domain reputation is damaged is very very hard to restore it, so it’s better to do the right thing from start.
6 observations on “Using a SMTP server to send Gravity Forms notifications
  1. Richard Hassell

    Hi Samuel,

    I was so excited just now to see this post. I cannot tell you how long I have been pulling out my hair with trying to find an SMTP plugin or syntax that did not take over the entire system! However, I just installed your plugin and it didnt work, same error as most of the other plugins 🙁 Gravity throws the error:

    2017-08-14 19:22:48.920948 – DEBUG –> GFCommon::send_email(): Result from wp_mail(): 1
    2017-08-14 19:22:48.921073 – DEBUG –> GFCommon::send_email(): Mail was passed from WordPress to the mail server.
    2017-08-14 19:22:48.921152 – DEBUG –> GFCommon::send_email(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.

    I added this as an issue on git, Any suggestions?

    1. Samuel Aguilera

      Hi Richard, there’s not any error in that log, I just replied your issue in Github please check it for more details.

  2. Robert

    Hi Samuel quick question, would it be possible to use 2 SMTP configurations for 2 different domains, sharing same IP and database? What I need is to send 2 notifications, but I need that one of them doesn’t display the other website email from or the “Sent via… ” in gmail for instance. I am trying to achieve that but I’m not sure if that is possible. Is there any way to get that done?

    Thank you

    1. Samuel Aguilera

      I’m not aware of any SMTP plugin capable of doing it. So you would need to hire someone to code a custom solution for you.

  3. Carol

    I found this article yesterday, and it really cleared things up for me! THANK YOU!

    I followed your directions and at first, my test email did not send. Then I noticed that the graphic in your article for the SMTP server details has slightly different information that what is listed to the left, for the smtp server details. There, you list the SMTP Server as smtp.sendgrid.com. In the graphic, it says smtp.sendgrid.net. When I changed it to the latter, my test email was sent and my problem was solved. Just FYI.


Leave Your Observation

Your email address will not be published. Required fields are marked *