please send me the code to generate auto generated email for frogot password
once the user fills the date of birth and user id he should get back his password through mail how do i do this

Because you shouldn't usually save a users password in the raw format, but instead save it as an ecrypted version using something like md5() you can't physically retrieve the users password.

Instead you could send out a reset email...

Im writting this on the fly. I haven't tested it, but should get you started. As mentioned above, storing encrypted passwords is how things are done. This script will create a new password and update the database, then send the new password to the user.

if(isset($_POST['recover_password']){

    if(isset($_POST['user_id']) && isset($_POST['user_email'])){

        $pattern = "/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ "; // regex validation for email
        if (preg_match($pattern, $email)) {
             $pass_len = 8; //Password Length

            $gen_rand_pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),0, $pass_len);// Generate a random string as the password.

            $encrypt_password = sha1($gen_rand_pass); //Use sha1 to encrypt the new random password to be inserted in the database.

            $query = mysql_query("INSERT INTO table SET password = $encrypt_password WHERE user_id = $id");
            if(!$query)die().mysql_error(); //Check if query has been run.

            $updated = mysql_affected_rows($query);

            if($updated == 1){
                //Email with password being sent to user.
                $to = $_POST['user_email'];
                $subject = "Password Recovery";
                $message = "<b>Password Recovery Program.</b>";
                $message .= "<p>New Password: ".$gen_rand_pass."</p>";
                $header = "From:no-reply@somedomain.com \r\n";
                $header .= "MIME-Version: 1.0\r\n";
                $header .= "Content-type: text/html\r\n";
                $retval = mail ($to,$subject,$message,$header);
                if( $retval == true )
                {
                echo "Message sent successfully...";
                }
                else
                {
                echo "Message could not be sent...";
                }
            }
        } else { 
             echo $email . \" is an invalid email. Please try again.\";
             exit;
        } 
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.