If you manage multiple email delivery services, you might want WordPress to use one SMTP provider for certain recipients (e.g. Microsoft addresses like @hotmail.com) and another provider for everyone else.
This can improve deliverability, reputation management, and success rates when sending to tricky domains. In particular, this method has been put together to address delivery issues with Microsoft's free email services, such as hotmail.com and live.com, that EmailIt continues to suffer from.
Fortunately, this can be done neatly in WordPress using FluentSMTP and a few lines of PHP.
Some email hosts handle certain destinations better than others. For example:
FluentSMTP already supports multiple SMTP connections — it simply chooses one based on the “From” email address. With a short code snippet, you can automatically switch that “From” address depending on the recipient domain.
Go to Settings → FluentSMTP → Settings and create two connections:
Primary connection (default)
[email protected]Secondary connection (for Microsoft addresses)
[email protected] (or any other alias you prefer)For my use case, my primary connection is with MailGun and the secondary with EmailIt.
FluentSMTP automatically chooses the connection based on the “From” address.
The code below will change that address dynamically depending on the recipient.
Add this snippet to your site using a code snippets plugin, a custom plugin, or your theme’s functions.php.
/**
* Route emails through different FluentSMTP connections depending on the recipient domain.
*
* Requires:
* - Primary FluentSMTP connection (default): e.g. [email protected]
* - Secondary FluentSMTP connection: e.g. [email protected]
*
* Adjust the domain lists and email addresses as needed.
*/
add_action( 'phpmailer_init', function ( $phpmailer ) {
if ( ! $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) {
return;
}
// Combine all recipient types (To, CC, BCC)
$recipients = array_merge(
(array) $phpmailer->getToAddresses(),
(array) $phpmailer->getCcAddresses(),
(array) $phpmailer->getBccAddresses()
);
if ( empty( $recipients ) ) {
return;
}
// Define which recipient domains should trigger the secondary route
$special_domains = [
'hotmail.com',
'hotmail.co.uk',
'outlook.com',
'outlook.co.uk',
'live.com',
'live.co.uk',
// Add more domains here if needed
];
$use_secondary = false;
foreach ( $recipients as $recipient ) {
$email = isset( $recipient[0] ) ? strtolower( trim( $recipient[0] ) ) : '';
if ( ! $email || strpos( $email, '@' ) === false ) {
continue;
}
$domain = substr( strrchr( $email, '@' ), 1 );
if ( in_array( $domain, $special_domains, true ) ) {
$use_secondary = true;
break;
}
}
if ( ! $use_secondary ) {
return; // send normally
}
// Switch the "From" to match the secondary FluentSMTP connection
$from_email = '[email protected]'; // secondary connection
$from_name = get_bloginfo( 'name' );
$phpmailer->setFrom( $from_email, $from_name, false );
$phpmailer->Sender = $from_email; // optional but recommended
}, 5 );
If you use both providers’ dashboards, you’ll also see the messages arriving through the expected route.
$special_domains array with any domain list you like.wp_mail() function.5 to ensure it runs before FluentSMTP’s internal routing.By combining FluentSMTP’s multi-connection feature with a simple PHPMailer hook, you can intelligently route WordPress emails based on the recipient domain — no extra plugin or service required.
It’s a lightweight, flexible way to: