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(mark@phpeasystep.com)
$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
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

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.

Guest
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.