How to Setup SMTP in WordPress Without a Plugin

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 it is 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 properly, 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 using a 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 doing you should first create the Child theme and do 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 values of the username, and password 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', '' );     
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 have to add the following lines to the function.php file present in the child theme.

add_action( 'phpmailer_init', 'my_phpmailer_smtp' );
function my_phpmailer_smtp( $phpmailer ) {
    $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;

Wrap Up

When you have technical skills, it is not necessary to use plugins for implementing SMTP in WordPress. 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

Subscribe to our newsletter

Get latest product updates and tips