PHP mail() vs SMTP: what's the difference?

PHP mail() vs SMTP: what's the difference?

Websites can send email (contact forms, order confirmations, password resets) in two ways.

PHP mail()

The website hands the message straight to the server's mail system. It's simple, but the email isn't tied to a real mailbox and isn't authenticated, so it's more likely to be marked as spam, especially if the From address is on another domain such as Gmail.

SMTP (recommended)

The website logs in to a real mailbox, exactly like an email app, and sends through it. Messages are authenticated and pass SPF/DKIM checks, so they're far more likely to arrive.

How to switch to SMTP

  • WordPress: use a plugin such as WP Mail SMTP (see How to send WordPress emails via SMTP)
  • Custom PHP: use a library such as PHPMailer with your mailbox settings: server hostname, port 465 (SSL) or 587 (TLS), full email address and password

Always send from an address on your own domain that exists as a mailbox.

    • Related Articles

    • How to send WordPress emails via SMTP

      In WordPress, go to Plugins › Add New Plugin, search for WP Mail SMTP and install and activate it. Go to WP Mail SMTP › Settings. Set From Email to a mailbox on your domain and tick Force From Email. Under Mailer, choose Other SMTP. Enter: SMTP Host: ...
    • How to change PHP version in cPanel

      Log in to cPanel and open MultiPHP Manager in the Software section. Tick the domain(s) you want to change. Choose the PHP version from the drop-down menu on the right and click Apply. The change takes effect immediately and only for the domains you ...
    • IMAP vs POP3: which should I use?

      IMAP and POP3 are the two ways an email app can collect your mail. IMAP (recommended) Mail stays on the server and is synced to each device Read, deleted and moved messages update everywhere Ideal if you use more than one device or webmail Uses your ...
    • How to use a custom domain with iCloud Mail

      With an iCloud+ subscription, you can use your own domain with iCloud Mail. Sign in at icloud.com, open Account Settings and find Custom Email Domain. Click Manage, choose who will use the domain and enter it. Apple shows the DNS records you need: MX ...
    • How to check PHP settings with phpinfo

      A phpinfo page shows the PHP version and settings your site is actually using. In cPanel File Manager, open public_html (or the folder for the domain you're checking). Click + File, name it something hard to guess such as info-82731.php, and create ...