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.

Why Switch to SMTP?

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.

How to Configure SMTP in WordPress

Follow these steps to set up SMTP on your WordPress site:

1. Install an SMTP Plugin

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\

  • Add Plugin
  • Search for WP Mail SMTP

  • Search
    Search

    WP Mail SMTP
    WP Mail SMTP
  • Click Install Now, then Activate

  • Install WP Mail SMTP
    Install WP Mail SMTP

    Activate WP Mail SMTP

2. Configure the Plugin Settings

Once installed:

  • Go to WP Mail SMTP > Settings
  • Under Mailer, choose your preferred email provider or Other SMTP

Example SMTP Settings (for Webmail):

  • SMTP Host: mail.yourdomain.com

  • Encryption: TLS/SSL

  • SMTP Port: 465

  • Authentication: Yes 

  • SMTP Username: Your full email address (e.g. you@domainname.com)

Example SMTP Settings (for Gmail):

  • 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)

  • WP Mail Settings
    WP Mail Settings

    WP Mail Config
    WP Mail Config

🔒 Never share or hard-code your SMTP password directly in files. Always store it securely using environment variables or WordPress constants.

3. Send a Test Email

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.

Troubleshooting Tips

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

Share This Article

Leave a Comment

Antimanual

Ask our AI support assistant your questions about our platform, features, and services.

You are offline
Chatbot Avatar
What can I help you with?
Order Services