Send WordPress email over SMTP: wp_mail with phpmailer_init, or a plugin
Two ways to make wp_mail use authenticated SMTP: a 15-line mu-plugin using the phpmailer_init hook (no plugin needed) or WP Mail SMTP with "Other SMTP". Where to store credentials in wp-config.php and how to test.
Install
# option A: no plugin — create wp-content/mu-plugins/smtp.php
Complete example
<?php
// wp-content/mu-plugins/smtp.php — loaded automatically, survives theme changes
add_action('phpmailer_init', function ($phpmailer) {
$phpmailer->isSMTP();
$phpmailer->Host = SMTP_HOST;
$phpmailer->Port = SMTP_PORT;
$phpmailer->SMTPSecure = SMTP_PORT == 465 ? 'ssl' : 'tls';
$phpmailer->SMTPAuth = true;
$phpmailer->Username = SMTP_USER;
$phpmailer->Password = SMTP_PASS;
$phpmailer->From = SMTP_FROM;
$phpmailer->FromName = SMTP_FROM_NAME;
});
// wp-config.php (above "That's all, stop editing!")
define('SMTP_HOST', 'smtp.queensmtp.com');
define('SMTP_PORT', 587);
define('SMTP_USER', 'your-smtp-username');
define('SMTP_PASS', 'your-smtp-password');
define('SMTP_FROM', 'hello@yourdomain.com');
define('SMTP_FROM_NAME', 'Your Site');
// test from WP-CLI
// wp eval 'var_dump(wp_mail("you@yourdomain.com", "SMTP test", "It works"));'What to know
- Option B: install WP Mail SMTP (or the QueenSMTP plugin), choose "Other SMTP", enter host smtp.queensmtp.com, port 587, encryption TLS, authentication on, and the same credentials. The plugin adds a log and a test button.
- WooCommerce order mail, password resets and contact forms all go through wp_mail, so this one change fixes every plugin.
- The From address must be on a domain you verified (SPF + DKIM) at the relay; a From of @gmail.com through another server fails DMARC.
- Hosts with hourly caps (cPanel "max emails per hour") do not apply when you relay externally — that is the usual reason stores switch.
Same code, different provider
Only the host, port and credentials change. The rules per provider are on the SMTP settings hub.
| Provider | Host | Port | Username | Password | Note |
|---|---|---|---|---|---|
| QueenSMTP | smtp.queensmtp.com | 587 (STARTTLS) / 465 (SSL) / 2525 | SMTP username from the dashboard | SMTP password | $5/year + $0.10 per 1,000; 100 free/day |
| Gmail | smtp.gmail.com | 587 / 465 | you@gmail.com | App Password | 500/day, From must be the account |
| Amazon SES | email-smtp.<region>.amazonaws.com | 587 / 465 / 2587 | SES SMTP username | SES SMTP password | sandbox 200/day until approved |
| Office 365 | smtp.office365.com | 587 | user@yourdomain.com | mailbox password | SMTP AUTH must be enabled; 30/min |
| SendGrid | smtp.sendgrid.net | 587 / 465 / 2525 | apikey | API key | no free plan since 2025 |
Credentials for the example above
Create a free account, verify your sending domain (SPF + DKIM shown in the dashboard), add an SMTP credential, and paste it into the code. 100 emails a day free; $5/year plus $0.10 per 1,000 after that. Prefer HTTPS? The same account has a REST email API.
Get SMTP credentials Test your settings firstOther languages and frameworks
WordPress SMTP — questions
Yes — hook phpmailer_init in a must-use plugin (15 lines above) and define the SMTP constants in wp-config.php. Plugins add logging and a test UI on top of the same mechanism.
WP Mail SMTP with the "Other SMTP" option works with any provider; the QueenSMTP plugin pre-fills our host and ports. Both use PHPMailer underneath.
Related Guides
Continue learning with these related articles