Skip to content

Instantly share code, notes, and snippets.

@RadGH
Last active December 19, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RadGH/5952163 to your computer and use it in GitHub Desktop.
Save RadGH/5952163 to your computer and use it in GitHub Desktop.
Change the default "From" address for Wordpress.
<?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