I am making a website with a forgot password script. The script send the user a temporary 8 digit passcode, which I am randomly generating. I wrote the code and spent quite some time debugging it, but I still get a server error. I am not sure what the error in the code is, and I know it's not in the server because there is no console message.
Here is my code:
<?php
include '../conn.php';
$email = mysqli_real_escape_string($conn, $_POST["email"]);
$check_query = "SELECT * FROM users WHERE email='$email'";
$check_result = mysqli_query($conn, $check_query);
$check_rows = mysqli_num_rows($check_result);
$allchars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
$temppwd = "";
for ($x = 1, $x < 9, $x++) {
$ranodmnum = rand(1, 36);
$temppwd = $temppwd + $allchars[$randnum];
}
function sendMail($to) {
$subject = "Password Reset Request for Pinder";
$msg = "You have requsted to reset your password for Pinder. This is your temporary password: " + $temppwd + "You will have to change it next time you login.";
mail($to, $subject, $msg);
}
if ($check_rows > 0) {
sendMail($email);
} else {
echo "Sorry, but there is no account associated with that email address!";
}
?>
Aucun commentaire:
Enregistrer un commentaire