Code php for make forgot password

Code php for make forgot password and send password to email member.

Make file with name:
1. forgot_password.php
2. send_password_ac.php

Make database with name member:
=$_POST['email_to']; "SELECT password FROM table_name WHERE email='$email_to'"
Create table "members"
This is our databasetable "Members" gspot password is "checkpass" and his e-mail is ""
 CREATE TABLE `members` (
idint(4NOT NULL auto_increment,
namevarchar(65NOT NULL default '',
lastnamevarchar(65NOT NULL default '',
emailvarchar(65NOT NULL default '',
passwordvarchar(65NOT NULL default '', PRIMARY KEY (`id`)

Dumping data for table `test_mysql`
INSERT INTO `membersVALUES (1'Anderson''pass1''''789789'); INSERT INTO `membersVALUES (2'Billy''pass2''''654123ddf'); INSERT INTO `membersVALUES (3'Andy''pass3''''951412dwe');
* replace email_1, 2 , 3 with your email for testing..

Make form with text field, name that text file and point with "email_to" action at "send_password_ac.php"
<table width="380" border="0" cellpadding="3" cellspacing="1" >
<td width="33%"><strong>Enter your email : </strong></td>
<td width="67%"><form name="form1" method="post" action="send_password_ac.php">
<input name="email_to" type="text" id="mail_to" size="25">
<input type="submit" name="Submit" value="Submit">


$host="localhost"// Host name
$username=""// Mysql username
$password=""// Mysql password
$db_name=""// Database name

//Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

// value sent from form

// table name

// retrieve password from table where e-mail = $email_to(
$sql="SELECT password FROM $tbl_name WHERE email='$email_to'";

// if found this e-mail address, row must be 1 row
// keep value in variable name "$count"

// compare if $count =1 row


// keep password in $your_password

// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...

// Your subject
$subject="Your password here";

// From
$header="from: your name <your email>";

// Your message
$messages"Your password for login to our website \r\n";
$messages.="Your password is $your_password \r\n";
$messages.="more message... \r\n";

// send email
$sentmail mail($to,$subject,$messages,$header);


// else if $count not equal 1
else {
echo "Not found your email in our database";

// if your email succesfully sent
echo "Your Password Has Been Sent To Your Email Address.";
else {
echo "Cannot send password to your e-mail address";


This script just for learn you can make it better...