2026年11月12日

2026年11月12日

How to Change the WordPress Email From Address and Sender Name

This article is a localized edition of the Japanese original. Read the Japanese original

Emails sent by WordPress (password resets, new user notifications, comment notifications and so on) use the following sender unless you change it:

  • Sender name: WordPress
  • Address: wordpress@ + your site's domain (the host name of the Site Address under "Settings" → "General", with any leading www. removed. For example, https://www.example.com gives wordpress@example.com)

If that mailbox does not exist, replies go nowhere, and recipients see an unfamiliar sender. This article shows how to change the sender to an address on your own domain and your site name.

Code to change the sender

Every time WordPress sends an email, it runs two filters: wp_mail_from (address) and wp_mail_from_name (sender name). Hook a function into them to change the sender.

So that it keeps working when you switch themes, it is best to put the following file in wp-content/mu-plugins/ (create the folder if it does not exist). It also works in a child theme's functions.php.

wp-content/mu-plugins/mail-from.php:

<?php
/*
 * Plugin Name: Mail From
 */

// From address: replace it only when it is the WordPress default (wordpress@...)
add_filter( 'wp_mail_from', function ( $email ) {
    if ( str_starts_with( $email, 'wordpress@' ) ) {
        return 'noreply@example.com';
    }
    return $email;
} );

// Sender name: replace it with the site name only when it is the default "WordPress"
add_filter( 'wp_mail_from_name', function ( $name ) {
    if ( 'WordPress' === $name ) {
        return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    }
    return $name;
} );

Replace noreply@example.com with an address on your own domain. str_starts_with() requires PHP 8.0 or later.

Why replace only the default

These filters also run when a plugin such as Contact Form 7 sets the From address in the email headers. If you unconditionally return 'noreply@example.com';, you also overwrite the sender configured in the plugin. Replacing only the default, as in the code above, leaves plugin settings intact. If you want every email to use the same sender, remove the condition.

Why not use the site name as-is

The site name has HTML special characters converted when it is saved, so a site named A & B is stored as A &amp; B. If you use get_bloginfo( 'name' ) directly, &amp; appears in the sender name, so the code decodes it with wp_specialchars_decode(), just as WordPress core's own email code does.

Use a different sender for specific emails

To use a different sender for a particular email, add a From header to that email. Since WordPress 6.0, you can change the password reset email with the retrieve_password_notification_email filter.

<?php
// Change the sender only for the password reset email (WordPress 6.0 and later)
add_filter( 'retrieve_password_notification_email', function ( $email ) {
    $email['headers'] = 'From: Example Security <security@example.com>';
    return $email;
} );

Combined with the "replace only the default" code above, this email is sent from security@example.com and everything else from noreply@example.com.

Checking with doing_action() inside the retrieve_password_message filter does not work. That filter runs while the message body is being built and has already finished by the time wp_mail_from is called.

Align the Return-Path (envelope sender) too

Besides the From address shown to the reader, an email has a sender address used for delivery (the envelope sender, recorded as Return-Path in the received message). SPF checks the domain of this address.

WordPress sets only the From address, not the envelope sender. On servers that send with PHP's mail(), the envelope sender may end up as something like username@server-hostname, which does not match the From domain. To align them, set PHPMailer's Sender to the From address in the phpmailer_init action.

<?php
// Make the envelope sender (Return-Path) the same as From
add_action( 'phpmailer_init', function ( $phpmailer ) {
    if ( empty( $phpmailer->Sender ) ) {
        $phpmailer->Sender = $phpmailer->From;
    }
} );

If you use an SMTP plugin, it often handles this already, so check the plugin's settings first.

Set up SPF and DKIM

Once the sender uses your own domain, set up sender authentication for that domain. Google's Email sender guidelines (as of November 2026) require everyone who sends to Gmail to set up SPF or DKIM (senders of more than 5,000 messages a day need both SPF and DKIM, plus DMARC).

For SPF, list the servers and services you send from in a DNS TXT record.

example.com.  IN  TXT  "v=spf1 ip4:203.0.113.10 include:_spf.example-mail.net ~all"
  • Put your server's IP address in ip4: if WordPress sends directly from that server.
  • Put the value provided by your external SMTP service or hosting company in include: (the _spf.example-mail.net above is an example).
  • Keep only one SPF record per domain. If there are several, SPF evaluation returns an error.

How to set up DKIM depends on the server or service that sends the mail. Follow the instructions from your hosting company or SMTP service.

Notes when sending through SMTP

  • Some SMTP servers reject mail, or replace the From address with the account's address, when From differs from the account you logged in with. With Gmail and Google Workspace SMTP, you can only use addresses registered as send-as addresses for that account.
  • SMTP plugins have their own sender settings, which may take precedence. Make sure the code and the plugin do not set conflicting values.

Send a test email

If you have WP-CLI, send an actual email with the following command. Replace you@example.com with an address you can receive.

wp eval 'var_dump( wp_mail( "you@example.com", "From test", "This is a test." ) );'

If it prints bool(true), WordPress handed the message off for sending (whether it arrives is a separate question). bool(false) means sending failed. You can find the reason with the wp_mail_failed action.

<?php
// Log the reason for a failed send to debug.log (enable WP_DEBUG_LOG first)
add_action( 'wp_mail_failed', function ( $error ) {
    error_log( 'wp_mail_failed: ' . $error->get_error_message() );
} );

In the received email, check the displayed sender, then open the message headers and check the following (in Gmail, use "Show original" in the message menu).

Header What to check
From Shows the sender name and address you set
Return-Path Uses the same domain as From
Authentication-Results Shows spf=pass and dkim=pass

Summary

  • The default WordPress sender is WordPress <wordpress@your-domain>.
  • Change it with wp_mail_from and wp_mail_from_name. Replacing only the default keeps senders set by plugins intact.
  • For SPF, align the Return-Path with From in phpmailer_init, and set up SPF and DKIM for the sending domain.
  • After the change, send a test email and check the From, Return-Path and Authentication-Results headers.

For SMTP setup when emails are not delivered, see WordPress SMTP setup; to check DNS, see how to check SPF, DKIM and DMARC.

Questions about WordPress? The publisher of this site is based in Japan and replies in Japanese. Contact (Japanese)

お気軽にご相談ください

お見積りへ お問い合わせへ
▲