Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host="localhost"; // Host name - update all those fields
- $username="xxxxx"; // Mysql username
- $password="xxxx"; // Mysql password
- $db_name="xxxxxx"; // 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['email_to']; // table name
- $tbl_name=tz_members;
- // retrieve password from table where e-mail is equal
- $sql="SELECT usr, pass, regIP 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);
- $your_username=$rows['usr']; $your_password=$rows['pass']; $your_ip=$rows['regIP']; $pass = substr(md5($your_ip.microtime().rand(1,100000)),0,6); // create a new pass
- mysql_query(" UPDATE tz_members SET pass='".md5($pass)."' WHERE email='".$email_to."'"); // update the db
- // ---------------- SEND MAIL FORM ---------------- // send e-mail to ...
- $to=$email_to;
- // Your subject
- $subject="Your password here";
- // From
- $header="from: your name ";
- // Your message
- $messages= "Your password for login has been reset.rn"; $messages.="The new password is $pass rn"; $messages.="Regards rn";
- // send email
- $sentmail = mail($to,$subject,$messages,$header);
- mysql_free_result($result); }
- // else if
- $count not equal 1 else if ($count==0) echo "Your email was not found in our database"; else echo "More than one (".$count.") email records was found in our database, please contact the administrator.";
- // if your email succesfully sent
- if($sentmail) { echo "The new password has been reset and sent to the email on record."; } else { echo "Cannot send the password to this e-mail address"; }
- ?>
- // else if
- $count not equal 1 else if ($count==0) echo "Your email was not found in our database";
- else echo "More than one (".$count.") email records was found in our database, please contact the administrator.";
- // else if $count not equal 1
- else if ($count==0) echo "Your email was not found in our database";
- else echo "More than one (".$count.") email records was found in our database, please contact the administrator.";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement