How To Set SMTP Setting in WordPress?

Have you ever faced the issue of trying to retrieve your WordPress password when the system does not send any emails?

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

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

What can we do in that case?

The answer Is ” Use an SMTP server“. In this article, we will learn How To Set SMTP Setting in WordPress with or without a plugin.

What Is SMTP ( Simple Mail Transfer Protocol)

SMTP is a mail transfer protocol for sending, receiving, and relaying emails. SMTP servers typically use TCP on port 25 or 587.

SMTP server works independently, and sending transactional emails from WordPress is a reliable option.

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

Using SMTP servers is more important for eCommerce stores, as 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 your full potential, you must opt for premium plans.

How To Set SMTP Setting in WordPress?

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

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

How To Configure WordPress SMTP Without A Plugin

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

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

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

Once you sign up for the SMTP service, you will get the credentials 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’s function.php file. Otherwise, whenever your theme is updated, 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. You will receive all 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. You have the choice.

I would recommend a free plugin, Easy WP SMTP, which 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.

SMTP Setting in WordPress

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.

SMTP Setting in WordPress

Conclusion: SMTP Settings In WordPress

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

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

If you encounter any issues in setting up SMTP, please write in the comment section, and I will assist you.

FAQ: WP Mail SMTP Setup

How To Configure SMTP In WordPress?

You can configure SMTP in WordPress using the Easy WP SMTP plugin, a free plugin that achieves the functionality.

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