以下代码是将忘记密码发送到用户邮件。
邮件仅发送到网络邮件,即(官方电子邮件ID),而不是传递给Yahoo邮件ID和Gmail邮件。
我不知道我在哪里犯了错误请帮帮我
<?php
session_start(); // Start Session
//Connect to the database through our include
include_once "connect_to_mysql.php";
session_register("session");
// This is displayed if all the fields are not filled in
$empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back";
// Convert to simple variables
$email = $_POST['email'];
if (!isset($_POST['email'])) {
?>
<?php
}
elseif (empty($email)) {
echo $empty_fields_message;
}
else {
$email=mysql_real_escape_string($email);
$status = "OK";
$msg="";
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {
$msg="Your email address is not correct<BR>";
$status= "NOTOK";}
echo "<br><br>";
if($status=="OK"){ $query="SELECT email,username FROM members WHERE email = '$email'";
$st=mysql_query($query) or die("Database error");
$recs=mysql_num_rows($st);
$row=mysql_fetch_object($st);
$em=$row->email;// email is stored to a variable
if ($recs == 0) {
//Redirect to denied page.
print "<script language='Javascript'>document.location.replace('forgotenpass_denied.php');</script>";
}
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$password = md5($random_password);
$sql = mysql_query("UPDATE members SET password='$password' WHERE email='$email'");
$to = "$email";
$from = "geetha.victor@tryteksolutions.com";
$subject = "Your Password Has been reset";
$message = "Hi, we have reset your password.
Your New Password is: $random_password
http://www.trytek.tryteksolutions.co.in/login.php
Once logged in you can change your password
Thanks!
Admin
This is an automated response, DO NOT REPLY!";
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
// Finally send the activation email to the member
mail($to, $subject, $message, $headers);
print "<script language='Javascript'>document.location.replace('forgotenpass_sucess.php');</script>";
}
else {echo "<center><font face='Verdana' size='2' color=red >$msg <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
}
?>