Last active
December 19, 2015 11:59
-
-
Save RadGH/5952163 to your computer and use it in GitHub Desktop.
Change the default "From" address for Wordpress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function change_wp_mail_sender( $phpmailer ) { | |
$from_name = 'My Website'; | |
$from_email = get_option('admin_email'); // The same email seen in Settings > General | |
if ( | |
// We should always have these parameters, but it doesn't hurt to avoid errors in the future | |
property_exists( $phpmailer, 'From' ) | |
&& property_exists( $phpmailer, 'FromName' ) | |
) { | |
// Check if the from address is the same as default in pluggable.php | |
if ( $phpmailer->From == 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) ) { | |
$phpmailer->From = $from_email; | |
} | |
// Check if the from name the same as in pluggable.php | |
if ( $phpmailer->FromName == 'WordPress' ) { | |
$phpmailer->FromName = $from_name; | |
} | |
} | |
} | |
add_action( 'phpmailer_init', 'change_wp_mail_sender' ); | |
// You might also want to use the filters: wp_mail_from, wp_mail_from_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment