Switch to Sending Email via SMTP (PHP Mail Alternative) in WordPress
By default, WordPress uses the PHP mail() function to send emails, whether for contact form notifications, user registrations, or password resets. While this works in many cases, it often results in emails being flagged as spam or not sent at all due to server restrictions.
A more reliable and secure way to handle email delivery in WordPress is by using SMTP (Simple Mail Transfer Protocol). SMTP ensures proper authentication and greatly improves the deliverability of your site’s emails.
Here are a few reasons to consider switching:
Improved deliverability: SMTP servers are designed to handle email routing properly.
Avoid spam filters: SMTP sends emails with proper headers and authentication, reducing the chance they’ll be flagged as spam.
Debugging tools: Most SMTP plugins offer logging and error reporting.
Better compatibility with external providers: Easily connect to Gmail, Outlook, SendGrid, Mailgun, or any email provider.
Follow these steps to set up SMTP on your WordPress site:
There are several reliable SMTP plugins. Popular choices include:
WP Mail SMTP by WPForms (recommended)
Easy WP SMTP
Post SMTP Mailer/Email Log
To install WP Mail SMTP:
Go to Plugins > Add New\

Search for WP Mail SMTP


Click Install Now, then Activate


Once installed:
SMTP Host: mail.yourdomain.com
Encryption: TLS/SSL
SMTP Port: 465
Authentication: Yes
SMTP Username: Your full email address (e.g. you@domainname.com)
SMTP Host: smtp.gmail.com
Encryption: TLS
SMTP Port: 587
Authentication: Yes
SMTP Username: Your full Gmail address (e.g. you@gmail.com)
SMTP Password: App Password (not your regular Gmail password — create it in your Google Account settings under 2FA > App Passwords)


🔒 Never share or hard-code your SMTP password directly in files. Always store it securely using environment variables or WordPress constants.
After configuring:
Go to WP Mail SMTP > Tools
Enter a recipient email address and click Send Email
You should receive a test message. If it fails, the plugin will display error logs to help troubleshoot.
Emails not sending? Check SMTP authentication, port, and host values.
Two-factor authentication issues? Use an App Password instead.
Firewall blocking SMTP port? Ensure ports like 587, 465, or 25 are open on your server.
Hosting restrictions? Some hosts block mail() and restrict SMTP usage—reach out to your hosting provider for clarification.
Switching from PHP’s mail() function to SMTP in WordPress is one of the best steps you can take to improve your site’s email reliability. With just a few minutes of setup, you can drastically reduce email issues and ensure that your users receive notifications, confirmations, and password resets as expected.