Guide · PHP
How to send email with WordPress
Make WordPress emails (contact forms, WooCommerce orders, password resets) reliable by routing wp_mail() through the Stack Emails SMTP relay.
Last reviewed November 2026
1. Set up
You need a Stack Emails API key (create one free) and a verified sending domain.
Install an SMTP plugin such as WP Mail SMTP or FluentSMTP and choose "Other SMTP":
| Setting | Value |
|---|---|
| SMTP host | smtp.stackemails.com |
| Encryption | SSL |
| Port | 465 |
| Authentication | On |
| Username | stackemails |
| Password | Your API key |
| From email | An address on your verified domain |
2. Send your first email
// Or without a plugin: configure PHPMailer from your theme or a small mu-plugin.
add_action("phpmailer_init", function ($phpmailer) {
$phpmailer->isSMTP();
$phpmailer->Host = "smtp.stackemails.com";
$phpmailer->Port = 465;
$phpmailer->SMTPSecure = "ssl";
$phpmailer->SMTPAuth = true;
$phpmailer->Username = "stackemails";
$phpmailer->Password = defined("STACKEMAILS_API_KEY") ? STACKEMAILS_API_KEY : "";
});
add_filter("wp_mail_from", fn () => "hello@mail.acme.com");
add_filter("wp_mail_from_name", fn () => "Acme");
A successful request returns 202 with the message id, for example { "id": "msg_5b1f0c6c2a8e4e0f", "status": "queued" }. Errors return a JSON body with error.code and error.message (see errors).
Define the key in wp-config.php (define("STACKEMAILS_API_KEY", "se_live_...");) rather than in the database. Many hosts block outbound port 25, but ports 465 and 587 to an authenticated relay are almost always allowed.
Production checklist
- Keep the API key in an environment variable or secret manager, never in client-side code.
- Add an
Idempotency-Keyheader to retries so a timeout never sends twice (idempotency). - Subscribe to webhooks for bounces and complaints.
- Check your domain's SPF, DKIM and DMARC records.
- Start from a tested email template for password resets, receipts and invites.