• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Swift Guides

Howtos, Tutorials & Guides

  • Home
  • Servers
  • Applications
  • Opinions
  • Search
You are here: Home / Applications / How to Configure WordPress SMTP without a plugin?

How to Configure WordPress SMTP without a plugin?

March 29, 2025 by Sourabh Verma

WordPress world is full of plugins and to be true, I don’t like them much. I want everything to be hard coded because it makes my WordPress admin less dirty, less messy and doesn’t bloat my website. I once used a SMTP plugin and from the next day, I started receiving many spam comments which freaked me out and that lead me to a conclusion that I will use as less plugin as possible.

How to Configure WordPress SMTP without a plugin
How-to-Configure-WordPress-SMTP-without-a-plugin

Table of Contents

  • Three steps to configure SMTP on WordPress without plugin
    • Step 1 – Add code to functions.php file
    • Step 2 – Get an app password for Gmail
    • Step 3 – Add code to wp-config.php

Anyways, configuring SMTP on WordPress is very easy, and thus you don’t need a plugin for such a small thing. So, let’s see how we can configure SMTP on WordPress to send emails.

Three steps to configure SMTP on WordPress without plugin

Step 1 – Add code to functions.php file

The first step is to add the given below code to your theme’s functions.php file

// Secure SMTP configuration using constants from wp-config.php
function custom_secure_smtp($phpmailer) {
    if (defined('SMTP_HOST') && defined('SMTP_USER') && defined('SMTP_PASS')) {
        $phpmailer->isSMTP();
        $phpmailer->Host = SMTP_HOST;
        $phpmailer->SMTPAuth = true;
        $phpmailer->Port = defined('SMTP_PORT') ? SMTP_PORT : 587;
        $phpmailer->Username = SMTP_USER;
        $phpmailer->Password = SMTP_PASS;
        $phpmailer->SMTPSecure = defined('SMTP_SECURE') ? SMTP_SECURE : 'tls';
        $phpmailer->From = SMTP_USER;
        $phpmailer->FromName = get_bloginfo('name');
    }
}
add_action('phpmailer_init', 'custom_secure_smtp');

Step 2 – Get an app password for Gmail

Since, we are using Gmail, we need to generate an app password because using your standard password won’t work. Here is how you can do it.

  1. Login to https://myaccount.google.com/
  2. Tap on “Security”
  3. Enable 2-Step verification because on then you can generate a passkey
  4. Scroll to “App passwords”
  5. Enter “app name” (can be anything) and click on “Create”
  6. Copy the key shown on the pop-up and paste it in notepad or any text editor as we need to use it in later steps

Step 3 – Add code to wp-config.php

Third and final step is to copy and paste the below code to your wp-config.php file. Make sure to make changes to the below code as per requirement.

// SMTP Configuration
define('SMTP_HOST', 'smtp.your-provider.com');
define('SMTP_USER', '[email protected]');
define('SMTP_PASS', 'your-email-password'); (if using gmail, use the app password that you have generated above)
define('SMTP_PORT', 587);
define('SMTP_SECURE', 'tls');

Save the file and it’s done. SMTP for your WordPress is configured.

Category: Applications Tagged In: wordpress

Like my work? Don't Forget to Share

Share on Facebook Share on Twitter Share on LinkedIn Share on Reddit Share on WhatsApp Share via Email

Hi, welcome to SwiftGuides! With over 12 years of experience in Linux, SysAdmin, databases, cloud computing, and other IT-related areas, I make sure publish easy-to-follow, 100% working tutorials. I hope you like my work. Thanks!

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

Stay With Us

Follow on Facebook Follow on Twitter Follow on LinkedIn Follow on Reddit Subscribe on YouTube Follow on Instagram

SwiftGuides: Howtos, Tutorials & Guides © 2025 · All Rights Reserved

  • Contact Us
  • Privacy Policy
  • Disclaimer