How to Setup SMTP in WordPress Without Plugin

SMTP in WordPress
April 14, 2026General

WordPress emails do not always reach inboxes reliably. This is a common problem for contact form notifications, password reset emails, order emails, and other important messages sent from your site.

One way to improve this is by using SMTP instead of relying on the default mail setup.

Many site owners use an SMTP plugin for this. But if you are comfortable editing WordPress files, you can also configure SMTP manually without installing another plugin.

This guide explains how that method works, when it makes sense to use it, and how to set it up step by step.

What This Method Does

By default, WordPress sends outgoing emails using its normal mail function.

With manual SMTP setup, you tell WordPress to send emails through your SMTP server instead. This gives you more control over how emails are sent and can improve delivery when the default setup is unreliable.

In this method, you will:

  • add your SMTP details in wp-config.php
  • configure WordPress to use those details through code
  • test your site emails after setup

This is a manual approach, so it is better suited to users who are comfortable editing WordPress files.

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.

Before You Start

Before you begin, make sure you have the details you need.

What you need

You will need:

  • access to wp-config.php
  • access to your theme files or another safe place to add custom code
  • your SMTP host
  • your SMTP username
  • your SMTP password
  • the correct SMTP port
  • the correct encryption type

What to be careful about

This method involves editing WordPress files directly. If the values are incorrect, your site emails may stop working.

That is why testing is an important part of the process. Do not treat the setup as complete until you confirm that emails are actually being delivered.

How WordPress SMTP Setup Works Without a Plugin

This setup works in two parts.

Add SMTP settings in wp-config.php

First, you store your SMTP details as constants in wp-config.php.

This keeps the main connection values in one place, such as the host, port, username, password, and encryption type.

Use code to apply the SMTP configuration

Next, you add a function that tells WordPress to use those SMTP settings when sending outgoing emails.

This is what switches WordPress from its default email path to your SMTP server.

Understanding these two parts makes the setup easier, because you are not just pasting code without knowing what it does.

Step 1: Add SMTP Settings in wp-config.php

Open your wp-config.php file and add your SMTP constants.

Use your own SMTP values in place of the example details.

define( 'SMTP_HOST', 'smtp.gmail.com' );
define( 'SMTP_PORT', '587' );
define( 'SMTP_SECURE', 'tls' );
define( 'SMTP_AUTH', true );
define( 'SMTP_USERNAME', '[email protected]' );
define( 'SMTP_PASSWORD', 'your-password' );

What these values mean

  • SMTP_HOST is your SMTP server address
  • SMTP_PORT is the port used for the connection
  • SMTP_SECURE is the encryption type, such as tls or ssl
  • SMTP_AUTH tells WordPress whether SMTP authentication is required
  • SMTP_USERNAME is your SMTP login username
  • SMTP_PASSWORD is your SMTP login password

Replace placeholder values carefully

Make sure each value matches your SMTP provider’s settings. A small mistake here can stop email delivery from working.

Save the file

After adding the constants, save the file before moving to the next step.

Step 2: Add SMTP Configuration in functions.php

Now you need to tell WordPress to use the SMTP settings you added.

Add the following code to your theme’s functions.php file of your child theme or another safe custom-code location.

add_action( 'phpmailer_init', 'configure_smtp' );

function configure_smtp( PHPMailer $phpmailer ) {
    $phpmailer->isSMTP();
    $phpmailer->Host       = SMTP_HOST;
    $phpmailer->SMTPAuth   = SMTP_AUTH;
    $phpmailer->Port       = SMTP_PORT;
    $phpmailer->Username   = SMTP_USERNAME;
    $phpmailer->Password   = SMTP_PASSWORD;
    $phpmailer->SMTPSecure = SMTP_SECURE;
}

What this code does

This function tells WordPress to use SMTP when sending emails.

It applies the SMTP values from wp-config.php and uses them in the mailer configuration.

Save the file carefully

Once the code is added, save the file and check that your site is still loading normally. If there is a syntax issue, it can break the page.

Step 3: Test Your WordPress Emails

This is one of the most important parts of the setup.

After adding the SMTP configuration, send a test email from your site. You can do this using a form notification, password reset email, or another normal WordPress email action.

Then check:

  • whether the email was actually received
  • whether it arrived in the inbox or spam folder
  • whether the sender details look correct
  • whether the message appears complete and readable

Do not assume the setup is working just because the code was saved successfully. Email delivery should always be tested after configuration.

Common Problems & Troubleshooting Tips

Manual SMTP setup can fail for several reasons. Here are some common ones to check.

Email is not being sent

If no email is being sent at all, review both files again and make sure the settings were added correctly.

SMTP host or port is incorrect

A wrong host name or port number can stop the connection from working.

Username or password is wrong

If the SMTP login details are incorrect, authentication will fail and WordPress will not be able to send emails through the server.

Encryption setting does not match the server

Make sure the encryption type matches the one required by your SMTP provider. If the server expects one type and your code uses another, the connection may fail.

Hosting environment is blocking the setup

In some cases, the server environment or hosting provider may affect outbound email configuration. If everything looks correct but emails still fail, the issue may be outside WordPress itself.

SMTP Without a Plugin vs SMTP Plugin

Both methods can work. The better choice depends on how you manage your site.

When manual setup is enough

Manual SMTP setup can be enough if:

  • you are comfortable editing WordPress files
  • you want a lightweight configuration
  • you do not need a settings screen in the dashboard

When an SMTP plugin may be the better option

A plugin-based setup may be easier if:

  • you want a dashboard interface
  • you want easier testing and updates
  • you do not want to edit code
  • multiple people manage the site

Conclusion

Configuring SMTP in WordPress without a plugin is possible if you are comfortable editing WordPress files.

The setup involves three main parts: adding SMTP settings in wp-config.php, applying them through code, or testing email delivery afterward.

This method can work well for users who prefer a manual setup. But if you want something easier to manage from the dashboard, a plugin-based approach to configure SMTP may still be the better option.

FAQs on Configuiring SMTP in WordPress

Can I use SMTP in WordPress without a plugin?

Yes. You can configure SMTP manually by adding settings in wp-config.php and using code to apply them in WordPress.

Which files do I need to edit?

You will usually need to edit wp-config.php and functions.php, or another safe custom-code location.

Is this method suitable for beginners?

It depends on your comfort level. If you are not used to editing WordPress files, a plugin-based SMTP setup may be easier.

Why is my test email not arriving?

Common reasons include incorrect SMTP host, port, username, password, or encryption settings. In some cases, the hosting environment may also affect delivery.

SHARE THIS POST
  • Good article, I have used this code in my current project. No need to install plugin for such simple task. It works! Now email pass SPF, DKIM, DMARC tests, before it was only SPF.

Leave a Comment