PhpWordpress Tricks

Send Forgot Password Email WordPress

Wordpress send pdf with wp_mail function

Send Forgot Password Email Wordpress


Hello, welcome to In this post, I will tell you How to Send Forgot Password Email WordPress? WordPress is the best cms. WordPress hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress.

In this post, I have made custom code for Send Forgot Password Email WordPress and you can add this into your wordpress forgot password template page.

If user forgot his/her password then we can use this code and send user password to user email.

And Now Final, here is the code for Send Forgot Password Email WordPress and you can add this code into your wordpress theme’s template file:

$random_password = wp_generate_password( 12, false );
$user = get_user_by( ’email’, $email );
$update_user = wp_update_user( array (
‘ID’ => $user->ID,
‘user_pass’ => $random_password
if( $update_user ) {
$to = $email;
$subject = ‘Your new password’;
$sender = get_option(‘name’);
$message = ‘Your new password is: ‘.$random_password;
$headers[] = ‘MIME-Version: 1.0’ . “\r\n”;
$headers[] = ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers[] = “X-Mailer: PHP \r\n”;
$headers[] = ‘From: ‘.$sender.’ < ‘.$email.’>’ . “\r\n”;
$mail = wp_mail( $to, $subject, $message, $headers );

There are so many tricks in wordpress and I will let you know all. Please do comment if you any query related to this post. Thank you.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL