Change Sender Name And Email in Outgoing WordPress Email.


How to change default sender name and email in outgoing WordPress email?

This can be done by many plugins but the real reason behind doing this using custom code is that Using too many plugins can harm your website or blog speed and performance which is not desirable by any site owner. that’s why we use custom code in most of the cases if the issue is not bigger like to change sender email and name is outgoing WordPress email.

By default, when we sends an email notification it uses ‘WordPress’ as the sender name. This looks unprofessional and we can change it to a real person or your website title.

Plugin like, Woocommerce give option in admin back-end to set email subject and send from email. but if we send our custom email it will take default ‘WordPress’ as the sender name. so we need to change this.

So to add custom code, first move to your WordPress theme function.php and use two wordpress hook.

  • 'wp_mail_from'
  • 'wp_mail_from_name'

We can easily change that by adding this code to our theme’s functions file.

For Changing mail from email.

// Function to change email address
function ChangeSenderEmail( $email ) {
    return '[email protected]';
}
add_filter('wp_mail_from','ChangeSenderEmail');

For Changing mail from Name.

// Function to change sender name
function ChangeSenderEmailName( $name) {
     return 'Xyz Scott';
}
add_filter('wp_mail_from_name','ChangeSenderEmailName');

For Changing mail from Name only when from Name is default ‘WordPress’.

Some plugin like Woocommerce as we discuss , modify send from name ,so if we want to modify name only if it’s not already modified then we need to use “if” conditional statement .

// Function to change sender name
function ChangeSenderEmailName($name){
  if($name	==	'WordPress'){
    return 'Xyz Scott';
  }else{
    return $name;
  }
} 
add_filter('wp_mail_from_name','ChangeSenderEmailName');
,

Leave a Reply

Your email address will not be published. Required fields are marked *