settings.php, file where the important MySQL information is located.
<?php
//CONNECTS TO YOUR DATABASE (MODIFY TO YOUR OWN SETTINGS) $c = mysql_connect("server", "username", "password"); $db = mysql_select_db("your_database", $c);
$table = 'users';
?>
Code:
form.php, file with the form to submit the email address where the password would be sent.
<table>
<tr><td align="right">Email: </td><td align="left"><input id="email"> Type an email that you regularly check for the demo but it must match the one in the database. Change <b>"you@example.com"</b> in your database.</td></tr>
<tr><td align="right"></td><td align="left"><input onClick="fp()" type="button" value="Get Password"></td></tr>
<tr><td align="right"></td><td align="left"><span id="message"></span></td></tr>
</table>
</body>
</html>
send-password.php, AJAX file which checks whether email is valid and if it exists, if so password will be sent to that address.
if($email_test){ include("settings.php"); //FILE WITH THE IMPORTANT MySQL INFORMATION
$server_un = 'you'; //USERNAME OF YOUR WEBSITE EMAIL ADDRESS (CHANGE TO YOUR OWN) Ex: admin $domain = $_SERVER["HTTP_HOST"]; //DOMAIN NAME WITH EXTENSION; Ex: (wcetdesigns.com) $server_email = $server_un.'@'.$domain; //YOUR WEBSITE'S EMAIL ADDRESS
$q = mysql_query("SELECT * FROM $table WHERE email='".$email."'"); $n = mysql_num_rows($q); $r = mysql_fetch_assoc($q);
if($n&&$r["email"]){ $to = $email; $subject = "Forgot Password"; $headers = "From: Your Site <".$server_email.">\r\n"; $headers .= "Content-type: text/html\r\n"; $message = "You have requested that you forgot your password.<br> Password: <b>".$r["password"]."<b>";
mail($to, $subject, $message, $headers);
echo 'Password sent to <b>'.$email.'</b>'; } } else { echo 'Invalid Email'; }
?>
1310
Views:3,427Downloads:596
(Optional in case you want a reply)
10 Comments
ada ghdfhdfhfdhgfdhfdhfdh
Saturday, April 27, 2013 at 2:55:08 PM
Guest it doen't showing any error but my mail is not sending ...im using local host...need any change in coding?pls any one help me at ishajohn890@gmail.com
Tuesday, Febuary 26, 2013 at 2:24:16 PM
vignesh i have a error in send-password.php Deprecated: Function eregi() is deprecated in D:\wamp\www\send-forgotten-password1360203085\send-password.php on line 12Waing: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\wamp\www\send-forgotten-password1360203085\send-password.php on line 16so please help me..............