How to Setup SMTP in WordPress Without Plugin

November 10, 2022General

Are you using so many plugins on your website and hesitant to use one more plugin to set up SMTP? Then this article is for YOU!

Here We will discuss how to configure SMTP without a plugin for sending and receiving emails. Let’s dive deep into the coding world.

What is SMTP, and Why is it Necessary for WordPress?

SMTP, or Simple Mail Transfer Protocol, is a mail transfer protocol for sending and receiving outgoing emails between senders and receivers. When an email is sent, it is transferred over the internet from one server to another using SMTP

WordPress, by default, is configured to use the PHP mail function to handle email services. But the PHP mail function is not configured correctly, and some service providers disable this mail function to reduce SPAM mail. The issue is that most WordPress companies need to have their servers appropriately configured with PHP mails.

To enhance the email functionality of WordPress, you can implement the Simple Mail Transfer Protocol or SMTP server to WordPress.

How to Configure SMTP in WordPress without Plugin?

To manually configure SMTP in WordPress, you need two files to be edited that is wp-config.php and function.php.

WordPress Configuration File (wp-config.php): This file can be located under the WordPress root directory. You can edit this file using a file manager, FTP, or SSH terminal.

Theme Function File (function file): You can locate this file under the theme folder of your website. (It is highly recommended whatever changes you are making, you should first create the Child theme and make the necessary changes in the child theme only).

Email SMTP settings in wp-config.php

Open the wp-config.php file and write the code written here. You need to change the username and password values according to your requirements.

You can write the code anywhere in the wp-config.php file but before this line /* That’s all, stop editing! Happy blogging. */.

// SMTP email settings
define( 'SMTP_USERNAME', '[email protected]' );  
define( 'SMTP_PASSWORD', '1234567' );   
define( 'SMTP_SERVER', 'smtp.gmail.com' );     
define( 'SMTP_FROM', '[email protected]' );   
define( 'SMTP_NAME', 'webtechstreet' );  
define( 'SMTP_PORT', '587' );     
define( 'SMTP_SECURE', 'tls' );   
define( 'SMTP_AUTH', true );  
define( 'SMTP_DEBUG',   0 );  

Theme function file(function.php)

You must add the following lines to the function.php file in the child theme.

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;
}

If you do not have that much time for coding efforts, you can do this by using a plugin. Here are some best plugins mentioned in another blog article that you could use to configure SMTP. Click here to know about How to Configure SMTP in WordPress

Wrap Up

When you have technical skills, using plugins for implementing SMTP in WordPress is not necessary. Instead, you can enable this feature manually by editing two files, wp-config.php, under your website’s root directory and function.php of your active theme (preferred Child Theme). But if you want to use a plugin to configure SMTP, we have shortlisted a few SMTP plugins for you – How to configure SMTP for sending emails in WordPress.

SHARE THIS POST

Leave a Comment