In many cases, WordPress users rely on plugins to configure and send emails through SMTP. However, it’s entirely possible to set up SMTP without the need for a plugin, providing more control over your email configuration and reducing the number of additional tools on your site. In this guide, we’ll walk you through the steps to send emails from WordPress using SMTP without using a plugin, ensuring reliable email delivery and enhanced security.

Step 1: Gather Your Gmail SMTP Credentials
Before we begin, let’s briefly understand what SMTP is. SMTP (Simple Mail Transfer Protocol) is a standard protocol used to send emails on the internet. When you configure SMTP in WordPress, it will use this protocol to send emails from your website through a valid email server. In this guide, we’ll use Gmail’s SMTP server, which allows you to send emails reliably without needing any additional plugins.
To send emails from WordPress using Gmail’s SMTP server, you’ll need the following information:
- SMTP Domain: smtp.gmail.com.
- SMTP port: SSL port is 465 or TLS port is 587.
- Secure protocol: With port 465, use SSL. With port 587, use TLS.
- Email account: Your Gmail email address.
- Email Password: The Gmail account SMTP client password.
Step 2. Create a Gmail App Password to Use SMTP

To create an app and password on Google you can follow these steps:
- Sign in to your Google account
- Enable 2-step verification under “Security”.
- Under “Sign in to Google,” select “Two-step verification.”
- Scroll to the bottom of the page and choose “App passwords.”
- Select “Other (Custom name)” and name your application.
- Select “Other (Custom name)” and give your app a name.
- Click “ Generate ” to generate the application.
- Copy and save the password and move on to the next step to configure SMTP to send Mail in Wordpress without using Plugins.
Step 3: Add SMTP code to functions.php
There are several methods to add a PHP script to a WordPress site and make it functional, but the most common and straightforward way is to add it to the functions.php file. You can edit the provided configuration below with your application account and password, and then add it at the end of the functions.php file.
add_action( 'phpmailer_init', function( $phpmailer ) { if ( !is_object( $phpmailer ) ) $phpmailer = (object) $phpmailer; $phpmailer->Mailer = 'smtp'; $phpmailer->Host = 'smtp.gmail.com'; $phpmailer->SMTPAuth = true; $phpmailer->Port = 587; $phpmailer->Username = 'youmail@gmail.com'; $phpmailer->Password = '16 character application password'; $phpmailer->SMTPSecure = 'TLS'; $phpmailer->From = 'youmail@gmail.com'; $phpmailer->FromName = 'We'; });
Note: If you use this code to send emails via SMTP without a plugin, you should deactivate any other plugins that provide similar email functionality to avoid conflicts.
Step 4. Test sending email
To verify your SMTP setup, send a test email. You can also check by triggering WordPress’s built-in email features, such as user registration, admin login alerts, or contact form submissions.
By following these steps, you can successfully configure SMTP in your WordPress site without using a plugin. This will give you more control over your email settings and improve the deliverability of your emails.
If you experience delays in receiving email notifications, it could be due to WordPress’s cron function. For solutions, check out this guide on how to fix delayed email issues in WordPress.
Note: Gmail limits the number of emails you can send per day to prevent spam. Regular accounts can send up to 500 emails, while paid accounts (Google Workspace) can send 2,000. If you send too many, you’ll be blocked from sending for 24 hours. To send more, use a professional email service or upgrade to Google Workspace.
You can refer to more detailed information on Google’s support websites:
Thank you, I did it.