Jump to content

Emailing forgotten password


mikebyrne

Recommended Posts

Im coding a password retrival box for my site but instead of running the php the page just loads member_login.php when I press the send password button.

 

my code is:

 

      <form action="login.php" method="POST">
      <div align="right">Pleas enter your Login Name</b>

<BR>(This is the name you signed up with)</div>
    </td>
    <td width="50%">
      <input type="text" name="uname" size="12" maxlength="50" class="field">
    </td>
  </tr>
  <tr>
    <td class="bgrl">
      <div align="right">Please enter your <b>password</b></div>

    </td>
    <td width="50%" class="bgrl">
      <input type="password" name="pword" size="18" class="field">
    </td>
  </tr>
  <tr><td> </td>
    <td>
    <input type="submit" value="Login »" name="login_form" class="submit"></form></td>
  </tr>



  <tr><td colspan="2" class="genericside"><span class="t11bw">Forgotten your password?</span></td>
  </tr>
  <tr valign="top">
    <td class="alignright">
    <form name="passwordreminder" action="password.php" method="post">
    <input type="hidden" name="type" value="passwordreminder">
    Please enter your email here:</td>

<td><input type="text" name="reminderemail" class="field" maxlength="50"><br>
<input type="submit" value="Send Password »" class="submit">
    </form>

 

Password.php looks like

 

<?

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="admin"; // 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
$email_to=$_POST['passwordreminder'];

// table name
$tbl_name=adminusers;

// retrieve password from table where e-mail = $email_to([email protected])
$sql="SELECT password FROM $tbl_name WHERE email='$email_to'";
$result=mysql_query($sql);

// if found this e-mail address, row must be 1 row
// keep value in variable name "$count"
$count=mysql_num_rows($result);

// compare if $count =1 row
if($count==1){

$rows=mysql_fetch_array($result);

// keep password in $your_password
$your_password=$rows['password'];

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

// send e-mail to ...
$to=$email_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
if($sentmail){
echo "Your Password Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send password to your e-mail address";
}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/98835-emailing-forgotten-password/
Share on other sites

<input type="submit" value="Login »" name="login_form" class="submit"></form></td>

  </tr>

 

 

 

  <tr><td colspan="2" class="genericside"><span class="t11bw">Forgotten your password?</span></td>

  </tr>

  <tr valign="top">

    <td class="alignright">

    <form name="passwordreminder" action="password.php" method="post">

    <input type="hidden" name="type" value="passwordreminder">

    Please enter your email here:</td>

 

<td><input type="text" name="reminderemail" class="field" maxlength="50"><br>

<input type="submit" value="Send Password »" class="submit">

    </form>

 

form closes inside a form

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.