Skip to content

How To Send Email Notifications When User Profile Updates In WordPress

Most of the websites sends an automatic email notification when a user updates his profile. It’s good for security because the user can find out if his user profile is being updated without his permission.

It’s a simple script which automatically sends email notifications when user profile updates in WordPress by the user itself or by the WordPress admin. Adding this snippet to your current theme’s functions.php file will do the job:

function user_profile_update( $user_id ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = $user_info->user_email;
        $subject = "Profile Updated: ".$site_url."";
        $message = "Hello " .$user_info->display_name . "\nYour profile has been updated!\n\nThank you for visiting\n ".$site_url."";
        wp_mail( $to, $subject, $message);
}
add_action( 'profile_update', 'user_profile_update', 10, 2);

Leave a Reply

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