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 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.
Table of Contents
What Does This Method Actually Do?
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, and test your site emails after setup. This is a manual approach suited to users who are comfortable editing WordPress files.
Why Does WordPress Struggle with Email Delivery?
WordPress defaults to the PHP mail function for all outgoing emails. Most shared hosting servers are not properly configured for PHP mail, and some hosting providers disable it entirely to reduce spam. Because PHP mail has no authentication mechanism, emails sent through it are frequently flagged as spam or blocked by receiving mail servers before they reach the inbox.
SMTP adds authentication to outgoing emails. This tells receiving mail servers that the message is legitimate and originates from the claimed domain, which dramatically improves the chance it reaches its destination.
What Do You Need Before Starting?
Before beginning, confirm you have everything required for the setup.
What you need:
Access to your wp-config.php file, access to your theme’s functions.php file or another safe place to add custom code, your SMTP host address, your SMTP username, your SMTP password, the correct SMTP port number, and the correct encryption type.
What to be careful about:
This method involves editing WordPress files directly. If any value is incorrect, your site emails may stop working entirely. Testing is an essential part of the process, do not treat the setup as complete until you confirm emails are actually being delivered.
How Do You Configure SMTP in WordPress Without a Plugin?
This setup works in two parts: storing your SMTP credentials in wp-config.php, then adding code that tells WordPress to use them when sending emails.
Step 1: Add SMTP Settings in wp-config.php
Open your wp-config.php file and add the following constants using 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 — 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
Make sure each value matches your SMTP provider’s settings exactly. A small mistake here can stop email delivery from working. Save the file before moving to the next step.
Step 2: Add SMTP Configuration in functions.php
Now add the code that tells WordPress to use the SMTP settings you defined. Add the following to your child theme’s functions.php file 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;
}
This function hooks into WordPress’s phpmailer_init action, which fires every time WordPress sends an email. It applies your SMTP constants from wp-config.php and switches WordPress from its default email path to your SMTP server. Once the code is added, save the file and verify your site is still loading normally. A syntax error in functions.php can break page loading.
Step 3: Test Your WordPress Emails
After adding the SMTP configuration, send a test email from your site. Use a form notification, a password reset email, or any other normal WordPress email action to trigger a message.
Check that the email was received, that it arrived in the inbox rather than the spam folder, that the sender details look correct, and that the message content appears complete and readable. Do not assume the setup is working just because the code was saved successfully. Email delivery should always be tested and confirmed after configuration.
What Are Common Problems with Manual SMTP Setup?
Manual SMTP configuration can fail for several reasons. These are the most common ones to check.
Email is not being sent at all. Review both files again and confirm the settings were added correctly with no typos or missing quotation marks.
SMTP host or port is incorrect. A wrong hostname or port number stops the connection from establishing. Verify both against your SMTP provider’s documentation.
Username or password is wrong. If login details are incorrect, authentication fails and WordPress cannot send through the server. Check that the credentials are exactly as provided by your email service.
Encryption type does not match the server. Confirm the encryption setting in your code matches what your SMTP provider requires. If the server expects TLS and your code specifies SSL, or vice versa, the connection will fail.
Hosting environment is blocking outbound connections. Some hosting providers restrict outbound connections on common SMTP ports. If everything looks correct but emails still fail, contact your hosting provider to confirm whether outbound SMTP is allowed on your server
Plugin or No Plugin – Which Approach Is Right for You?
Both methods can work reliably. The better choice depends on how you manage your site and what level of control you need.
Manual SMTP setup is enough if you are comfortable editing WordPress files, you want a lightweight configuration that adds no plugin overhead, you do not need a dashboard interface for settings, and only one person manages the site’s technical configuration.
An SMTP plugin may be the better option if you want a settings screen in the WordPress dashboard, you want built-in testing and email logging tools, you do not want to edit code files directly, or multiple people manage the site and need to be able to update email settings without file access.
If you prefer the plugin-based approach, see the complete guide on how to configure SMTP in WordPress using a plugin for a full walkthrough of the most widely used SMTP plugins and service providers.
Frequently Asked Questions
Can I use SMTP in WordPress without a plugin?
Yes. You can configure SMTP manually by adding your SMTP credentials as constants in wp-config.php and then adding a function to functions.php that applies those settings using the phpmailer_init hook. This switches WordPress from its default PHP mail function to your chosen SMTP server without any plugin dependency.
Which files do I need to edit?
You need to edit wp-config.php to store your SMTP credentials as constants, and functions.php in your child theme (or another safe custom code location) to add the function that applies those credentials. Editing your parent theme’s functions.php directly is not recommended as theme updates will overwrite your changes.
Is this method suitable for beginners?
It depends on your comfort level with WordPress file editing. If you are not used to editing wp-config.php or functions.php, a plugin-based SMTP setup is easier and carries less risk of breaking your site. The manual method is better suited to users who are familiar with WordPress file structure and comfortable with code.
Why is my test email not arriving after setup?
The most common causes are an incorrect SMTP host address, the wrong port number, an incorrect username or password, or a mismatched encryption type. Check each value in wp-config.php against your email provider’s SMTP settings documentation. If all settings look correct, check whether your hosting provider allows outbound SMTP connections on your chosen port.
Conclusion
Configuring SMTP in WordPress without a plugin is a practical option for users comfortable with WordPress file editing. The setup has three parts: adding SMTP constants to wp-config.php, applying them through a phpmailer_init function in functions.php, and testing email delivery to confirm everything is working correctly. When set up properly, this method is lightweight and reliable.
To confirm that emails from your site are being sent and delivered correctly after setup, WP Mail Log by WPVibes logs every outgoing WordPress email with its delivery status, recipient, subject, and timestamp, useful for diagnosing any remaining delivery issues.
If you would prefer a plugin-based approach, see the guide on how to configure SMTP in WordPress using a plugin.



aeeon
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.