changing notification emails from WordPress @mydomain.net to something else

I use a very similar approach like John P Bloch and Bainternet, just a little bit more flexible, so I don’t have to change the mail address for any client:

<?php # -*- coding: utf-8 -*-
/*
 * Plugin Name: Filter System From Mail
 * Description: Sets the WP from mail address to the first admin’s mail and the from name to blog name.
 * Version:     2012.08.30
 * Author:      Fuxia Scholz
 * Author URI:  https://fuxia.me
 * License:     MIT
 */

if ( ! function_exists( 't5_filter_system_from_mail' ) )
{
    /**
     * First admin's e-mail address or blog name depending on current filter.
     *
     * See wp-includes/pluggable.php::wp_mail()
     *
     * @param  $input Name or email address
     * @return string
     */
    function t5_filter_system_from_mail( $input )
    {
        // not the default address, probably a comment notification.
        if ( 0 !== stripos( $input, 'wordpress' ) )
            return $input; // Not auto-generated

        return get_option( 'wp_mail_from' === current_filter()
            ? 'admin_email' : 'blogname' );
    }

    add_filter( 'wp_mail_from',      't5_filter_system_from_mail' );
    add_filter( 'wp_mail_from_name', 't5_filter_system_from_mail' );
}

Leave a Comment