Configure WordPress SMTP With Or Without Plugin

Have you ever faced the issue when you are trying to retrieve your WordPress password and the system was not sending any emails?

If yes, then it is due to your host blocking the PHP function that is used by WordPress to send emails. Many cloud host and VPS host blocks this PHP function to reduce spam and load on their server.

If the wp_mail() is blocked by your host, WordPress can not send any emails.

What we can do in that case?

The answer Is ” Use an SMTP server”. In this article, we will find out how you can Configure WordPress SMTP servers with or without a plugin.

But before that, we should know what the heck is this SMTP server.

What Is SMTP ( Simple Mail Transfer Protocol)

SMTP is a mail transfer protocol used to send, receive, and relay emails. SMTP servers typically use TCP on port 25 or 587.

SMTP server works independently and it is a reliable option to send transactional emails from WordPress.

SMTP servers are designed to handle a large volume of email traffic and provide better security and authentication for delivering emails.

Using SMTP servers is more important for eCommerce stores where the system needs to send thousands of transactional emails every hour.

Here are a couple of reputed SMTP service providers. Most providers have a free plan with limited functionalities. To explore the full potential, you need to opt for the premium plans.

How To Configure WordPress SMTP?

You can configure WordPress SMTP using two different methods. One is using a plugin and the other one is without a plugin.

Personally, I hate installing plugins for each and everything and I believe you hate it too. That is why adding a couple of lines in the function.php file makes more sense to me.

How To Configure WordPress SMTP Without A Plugin

First of all, you need to sign up for the SMTP server. You can choose any of the service providers listed above.

Personally, I like using SendInBlue as their plans are feature-rich and the free plan allows sending 300 emails per day.

For WooCommerce websites, Zepto Mail is the best and cheapest. They charge $2.50 per 10000 emails which is the cheapest in the industry.

Once you sign up for the SMTP service, you will get the SMTP credential that you need to add to the wp-config.php file.

Please add the following piece of code to your wp-config.php file located in the root directory.

define( 'SMTP_username', '[email protected]' );  // Username of the SMTP server
define( 'SMTP_password', 'xxxxxxx' );   // SMTP master password. For Gmail, it is your gmail password
define( 'SMTP_server', 'xxxxx.sendinblue.com' );     // SMTP server address-Get from the service prodiver
define( 'SMTP_FROM', '[email protected]' );   // Your from email address- Set that in the service prodiver dashboard
define( 'SMTP_NAME', 'RiansTech Admin' );   //  The name that will appear in emails-Set that in the service prodiver dashboard
define( 'SMTP_PORT', '587' );     // Server Port Number-Get that from the service provider
define( 'SMTP_SECURE', 'tls' );   // Keep it TLS unless your service prodiver ask you to use SSL
define( 'SMTP_AUTH', true );  // Keep it TRUE
define( 'SMTP_DEBUG',   0 );  // You can set it to 1 to debug any issue

Now add the following piece of code to your theme function.php file. It is preferable to add this code to your child theme function.php file. If not, whenever there is an update to your theme, you will lose all the customization.

add_action( 'phpmailer_init', 'my_phpmailer_smtp' );
function my_phpmailer_smtp( $phpmailer ) {
    $phpmailer->isSMTP();     
    $phpmailer->Host = SMTP_server;  
    $phpmailer->SMTPAuth = SMTP_AUTH;
    $phpmailer->Port = SMTP_PORT;
    $phpmailer->Username = SMTP_username;
    $phpmailer->Password = SMTP_password;
    $phpmailer->SMTPSecure = SMTP_SECURE;
    $phpmailer->From = SMTP_FROM;
    $phpmailer->FromName = SMTP_NAME;
}

That’s it. Now you will receive all your transactional emails in your inbox using the SMTP server.

How To Configure WordPress SMTP With A Plugin

There are hundreds of SMTP plugins available in the WordPress repository. Some are paid, and some are free. The choice is yours.

Personally, I would recommend a free plugin named Easy WP SMTP that does its job pretty well

By default, the plugin comes with support for four service providers. However, you can configure any SMTP service provider using the “Other SMTP” option.

Configure WordPress SMTP

If you choose any of the four supported SMTP providers, you will get the following window where you need to fill in all the information.

All the options are self-explanatory and you will get the data from your SMTP service provider.

Configure WordPress SMTP 1

Conclusion: WordPress SMTP Settings

Configuring SMTP servers in WordPress is very easy. You just need to add a few lines of code in the wp-config.php and Function.php file.

The code shared in this article is tested and working perfectly. In fact, I use the same code for RiansTech without any issues.

If you face any issues in setting up SMTP, please write in the comment section and I will help you out.

Rajib
Rajib

Rajib Is The Founder Of RiansTech. A Seasonal Blogger And A Full-Time Product Designer For Over Two Decades. A Technology Freak And Loves To Write About It. RiansTech Is A Online Home For Him Where He Documents His Experiences And Learnings So That Others Can Get Benefited From It.

      RiansTech
      Logo