-1

Is there a way to change ### ADMIN_EMAIL ### for all automatic notifications email in wordpress?

For example in change password notification and change email for user, I would like a custom email different form real admin email

If you did not change your email, please contact the Site Administrator at ###ADMIN_EMAIL###

If you did not change your email, please contact the Site Administrator at ###CUSTOM_EMAIL###

Meg
  • 11
  • 1

1 Answers1

1

You can use the filters:

  • password_change_email (source)
  • email_change_email (source)

and update the admin email address using str_replace().

Each of the above filters accepts 3 parameters (arrays):

  • $email_change_email or $pass_change_email (depending on filter used)
  • $user
  • $userdata

The first parameter has an array item called message which holds some strings which are dynamically replaced:

  • ###USERNAME### The current user's username.
  • ###ADMIN_EMAIL### The admin email in case this was unexpected.
  • ###EMAIL### The user's email address.
  • ###SITENAME### The name of the site.
  • ###SITEURL### The URL to the site.

Complete code:

Change other_email@your-domain.com to your new admin email address.

/**
 * Change admin email in notifications.
 *
 * This applies to password and email change notifications.
 *
 * @param (array) $pass_change_email Used to build wp_mail().
 * @param (array) The original user array.
 * @param (array) The updated user array.
 *
 * @return (array) $pass_change_email Updated wp_mail() content.
 */
add_filter('password_change_email', 'replace_admin_email_in_notification_emails', 10, 3);
add_filter('email_change_email', 'replace_admin_email_in_notification_emails', 10, 3);

function replace_admin_email_in_notification_emails( $pass_change_email, $user, $userdata ) {
  $pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', 'other_email@your-domain.com', $pass_change_email['message'] );

  return $pass_change_email;
}