我遇到了 PHP mail() 函数的一个主要问题。我有一个用户注册页面,它会生成一封电子邮件以验证他们的电子邮件地址。不幸的是,该功能向同一用户发送了 6 或 7 至 90 多封电子邮件。我不明白这是如何发生或为什么会发生的,即使在查看了其他人的帖子后也是如此。
有人可以帮我调试吗?
这是代码:
$first_name = mysql_real_escape_string($_POST['first_name']);
$last_name = mysql_real_escape_string($_POST['last_name']);
$email = mysql_real_escape_string($_POST['email']);
$username = strtoupper(mysql_real_escape_string($_POST['username']));
$password1 = mysql_real_escape_string($_POST['password1']);
$password2 = mysql_real_escape_string($_POST['password2']);
$termsofuse = mysql_real_escape_string($_POST['termsofuse']);
$status = mysql_real_escape_string($_POST['status']);
$approved = mysql_real_escape_string($_POST['approved']);
$acctype = mysql_real_escape_string($_POST['acctype']);
$industry = mysql_real_escape_string($_POST['industry']);
$newsletter = mysql_real_escape_string($_POST['newsletter']);
$contactname = mysql_real_escape_string($_POST['contactname']);
$contactnumber = mysql_real_escape_string($_POST['contactnumber']);
// Hashing of $password1
$password1 = sha256($password1);
$password2 = sha256($password2);
$hash = hash('sha256', $username);
// Check for existing username
$sql = "SELECT * FROM `members`";
$result2=mysql_query($sql);
while($row=mysql_fetch_array($result2)){
$username2 = $row['username'];
// If $username doesn't equal $username2 (meaning there isn't an existing username, and both passwords match, write to database
if($username <> $username2 && $password1 === $password2){
$sql = "INSERT INTO `members` (`id`, `first_name`, `last_name`, `email`, `username`, `password`, `termsofuse`, `status`, `approved`, `acctype`, `industry`, `newsletter`, `contactnumber`, `hash`, `since`) VALUES (NULL, '$first_name' , '$last_name' , '$email' , '$username' , '$password1' , '$termsofuse', 'Reg', '$approved', '$acctype', '$industry', '$newsletter', '$contactnumber', '$hash', NOW())";
$result = mysql_query($sql) or die ("Can't insert".mysql_error());
$to = $email; // Send email to user
$subject = 'Signup Verification'; //Subject line in email
$message = 'Welcome ' . $first_name . ','
. "\r\n\r\n"
. 'Thanks for signing up!'
. "\r\n\r\n"
. 'Your account has been created. To activate your account, click on the link below to get started!'
. "\r\n\r\n"
. 'http://www.radioman911.com/pages/CAD/verify.php?email=' . $email . '&hash=' . $hash . '';
$headers = 'From: xxxx' . "\r\n" .
'Reply-To: same xxxx as above' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers, '-fxxxx same as above'); //Send the email
header("location:new_member_sucess.php"); //yes, i know i spelled success wrong, but i also spelled it wrong in the page filename lol
} else {
echo "<style type='text/css'>A{text-decoration:none}</style>";
echo "<body bgcolor='black'><font color='white' style='font-family:trebuchet ms;'>";
echo "Passwords do not match or that username is already taken, please try again!<br>";
echo "<a href='javascript: history.go(-1)'><font color='red'>Go back</a></font>";
}
}
?>
谢谢!