Jump to content

Sending email for forgotten password


Recommended Posts

The program works with sending via email with the real password that exists in database...


Can anyone help me with sending a random password to the email instead of showing the real password out?





<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="root"; // Mysql username

//$password=""; // Mysql password

$db_name="registration"; // Database name



//Connect to server and select databse.

mysql_connect("$host", "$username")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(mark@phpeasystep.com)

$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";




Link to comment
Share on other sites

uhm whats the difference in using a random generated password and a real password?

instead of a password, just give them a link with a token and give it like 12 hr expiration period.


but ta will have to create a new table of these tokens and expiration period. just keep it simple :)


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.