The email_change_email WordPress PHP filter allows you to customize the email contents sent when a user’s email address is changed.
Usage
add_filter('email_change_email', 'your_custom_function', 10, 3); function your_custom_function($email_change_email, $user, $userdata) { // your custom code here return $email_change_email; }
Parameters
$email_change_email (array)
– Used to build wp_mail() with keys ‘to’, ‘subject’, ‘message’, and ‘headers’.$user (array)
– The original user array.$userdata (array)
– The updated user array.
More information
See WordPress Developer Resources: email_change_email
Examples
Customize the email subject
Change the email subject to include the website’s name.
add_filter('email_change_email', 'change_email_subject', 10, 3); function change_email_subject($email_change_email, $user, $userdata) { $email_change_email['subject'] = 'Your Email Has Been Updated on ' . get_bloginfo('name'); return $email_change_email; }
Add custom text to the email message
Add a custom message to the email sent when the user’s email is changed.
add_filter('email_change_email', 'add_custom_message', 10, 3); function add_custom_message($email_change_email, $user, $userdata) { $custom_message = "\n\nIf you did not request this change, please contact our support team."; $email_change_email['message'] .= $custom_message; return $email_change_email; }
Change email recipient
Send a notification to the admin when a user changes their email.
add_filter('email_change_email', 'send_notification_to_admin', 10, 3); function send_notification_to_admin($email_change_email, $user, $userdata) { $email_change_email['to'] = get_option('admin_email'); return $email_change_email; }
Add custom headers
Add a custom ‘Reply-To’ header to the email.
add_filter('email_change_email', 'add_custom_headers', 10, 3); function add_custom_headers($email_change_email, $user, $userdata) { $email_change_email['headers'] .= 'Reply-To: [email protected]' . "\r\n"; return $email_change_email; }
Change email content type
Change the email content type to HTML.
add_filter('email_change_email', 'change_email_content_type', 10, 3); function change_email_content_type($email_change_email, $user, $userdata) { $email_change_email['headers'] .= 'Content-Type: text/html' . "\r\n"; return $email_change_email; }