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:
- Your host blocks or throttles
mail(). Many managed and cloud hosts disable it to stop spam from hacked sites. - 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.
- The sender address is wrong. WordPress defaults to
wordpress@yourdomain.com, and some form plugins put the visitor’s address inFrom, 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.