Frameworks

How to set up SMTP in WordPress

Short answer

WordPress sends email with wp_mail(), which by default uses the server's PHP mail() function with no authentication, so password resets and form notifications often go to spam or vanish. To fix it, route wp_mail() through an authenticated SMTP server, either with an SMTP plugin such as WP Mail SMTP or FluentSMTP, or with a short phpmailer_init snippet. Then verify your domain with SPF, DKIM and DMARC.

Last checked 16 November 2026

WordPress sends every email, from password resets to WooCommerce order notices, through one function: wp_mail(). Out of the box it hands mail to PHP’s mail() function, which sends from your web server with no login and no signature for your domain. That is why WordPress email so often goes missing or lands in spam. The fix is to route wp_mail() through an authenticated SMTP server.

Why WordPress is not sending email

The common causes, in rough order:

  1. Your host blocks or throttles mail(). Many managed and cloud hosts disable it to stop spam from hacked sites.
  2. The mail is not authenticated. It leaves from the web server’s IP address, which your domain’s SPF record does not list, with no DKIM signature. Gmail, Outlook and Yahoo filter it.
  3. The sender address is wrong. WordPress defaults to wordpress@yourdomain.com, and some form plugins put the visitor’s address in From, which fails every authentication check.

SMTP through a transactional email provider fixes all three: the provider authenticates you, signs the mail with DKIM for your domain, and sends from servers your SPF record covers. Our guide on why emails go to spam covers other causes.

Option 1: an SMTP plugin

If you prefer a settings screen, install an SMTP plugin such as WP Mail SMTP or FluentSMTP. In WP Mail SMTP, pick the Other SMTP mailer and fill in:

Setting Value
SMTP host smtp.mailcandor.com (or your provider’s host)
Encryption SSL
SMTP port 465
Authentication On
SMTP username mailcandor
SMTP password Your API key
From email An address on your verified domain, such as hello@yourdomain.com

For TLS on port 587 instead, choose TLS encryption and port 587. Then use the plugin’s test email feature to check the connection. The SMTP ports guide explains the two ports.

Both plugins can store the password in wp-config.php instead of the database; check the plugin’s documentation for the constant names, and prefer that option on shared hosting.

Option 2: SMTP with a few lines of code

No plugin is needed. WordPress uses PHPMailer internally and fires the phpmailer_init action before every send, so you can configure SMTP there.

Add the key to wp-config.php, above the “That’s all, stop editing” line:

define( 'MAILCANDOR_KEY', 'mc_live_xxxxxxxxxxxxxxxx' );

Then create a must-use plugin at wp-content/mu-plugins/smtp.php. Files in mu-plugins load automatically and cannot be switched off from the dashboard:

<?php
/**
 * Plugin Name: SMTP for wp_mail
 */

add_action( 'phpmailer_init', function ( $phpmailer ) {
    $phpmailer->isSMTP();
    $phpmailer->Host       = 'smtp.mailcandor.com';
    $phpmailer->SMTPAuth   = true;
    $phpmailer->Port       = 465;
    $phpmailer->SMTPSecure = 'ssl';
    $phpmailer->Username   = 'mailcandor';
    $phpmailer->Password   = MAILCANDOR_KEY;
} );

add_filter( 'wp_mail_from', fn () => 'hello@yourdomain.com' );
add_filter( 'wp_mail_from_name', fn () => 'Your Site' );

add_action( 'wp_mail_failed', function ( $error ) {
    error_log( 'wp_mail failed: ' . $error->get_error_message() );
} );

For port 587, set Port to 587 and SMTPSecure to 'tls'. The wp_mail_failed hook writes failures to your PHP error log, so you can see why a message did not go.

To test, trigger a password reset for your own account, or run wp eval 'var_dump( wp_mail( "you@example.com", "Test", "It works" ) );' with WP-CLI.

Option 3: send through an email API instead

Some hosts block outbound SMTP ports entirely. If both 465 and 587 time out, you can short-circuit wp_mail() with the pre_wp_mail filter (WordPress 5.7 and later) and send over HTTPS instead:

<?php
/**
 * Plugin Name: wp_mail via email API
 */

add_filter( 'pre_wp_mail', function ( $return, $atts ) {
    $to      = is_array( $atts['to'] ) ? $atts['to'] : explode( ',', $atts['to'] );
    $headers = is_array( $atts['headers'] ) ? implode( "\n", $atts['headers'] ) : (string) $atts['headers'];
    $field   = stripos( $headers, 'text/html' ) !== false ? 'html' : 'text';

    $response = wp_remote_post( 'https://api.mailcandor.com/v1/emails', array(
        'timeout' => 10,
        'headers' => array(
            'Authorization' => 'Bearer ' . MAILCANDOR_KEY,
            'Content-Type'  => 'application/json',
        ),
        'body'    => wp_json_encode( array(
            'from'    => 'Your Site <hello@yourdomain.com>',
            'to'      => array_map( 'trim', $to ),
            'subject' => $atts['subject'],
            $field    => $atts['message'],
        ) ),
    ) );

    return ! is_wp_error( $response ) && 202 === wp_remote_retrieve_response_code( $response );
}, 10, 2 );

This version is deliberately simple: it ignores attachments, CC and custom headers that plugins pass to wp_mail(). If your site sends invoices or other attachments, stick with SMTP, which handles every wp_mail() feature.

Still not working?

Check the PHP error log for messages from wp_mail_failed. “Could not authenticate” means wrong credentials; “SMTP connect() failed” usually means your host blocks the port, which is when Option 3 helps.

Which should you choose?

SMTP plugin phpmailer_init snippet API via pre_wp_mail
Settings screen and test button Yes No No
Extra plugin to maintain Yes No No
Handles attachments and headers Yes Yes Not in this simple version
Works when SMTP ports are blocked No No Yes

For most sites, either SMTP option is right. Choose the plugin if non-developers manage the site; choose the snippet if you keep configuration in code. Mailcandor’s SMTP relay works with both.

Before you send: verify your domain

SMTP fixes the connection, but receiving servers still check your domain. Add your domain with your email provider, publish the SPF, DKIM and DMARC records it gives you, and make sure the from address uses that domain. The SPF, DKIM and DMARC guide explains each record.

Questions

Why is WordPress not sending email?

By default wp_mail() uses PHP's mail() function, which many hosts disable or throttle, and which sends without authentication for your domain. The mail is blocked or filtered. Sending through authenticated SMTP fixes most cases.

Do I need an SMTP plugin for WordPress?

No. A plugin gives you a settings screen and a test button, but a few lines in a must-use plugin do the same job through the phpmailer_init hook.

What SMTP settings do I enter in WP Mail SMTP?

Choose the Other SMTP mailer, then enter your provider's SMTP host, port 465 with SSL or port 587 with TLS, authentication on, and the username and password your provider gives you.

Will SMTP fix WooCommerce and contact form emails?

Yes. WooCommerce, Contact Form 7, Gravity Forms and most other plugins send through wp_mail(), so they all use the SMTP connection once it is configured.

What is WordPress transactional email?

The automatic messages WordPress and its plugins send to one person at a time: password resets, new user notices, order confirmations and form notifications. They need reliable delivery, which is why a transactional provider is recommended.

Related

Send with someone on your side.

Unlimited domains on every plan, a person before any block, and 3,000 emails a month free. Tell us what you send and we set you up within one business day.