I have the following code, if you do not make a particular request it issues an error, if there is no such error send email to the user. the problem is that in addition to appearing the error and also send the email (see the photo).
<?php
include("config.php");
if(isset($_POST\['submit_email'\]) && isset($_POST\['email'\])) {
$email = mysqli_real_escape_string($conn, $_POST\['email'\]);
$sql = "SELECT * FROM registo WHERE email = '$email'";
$r = mysqli_query($conn, $sql);
$count = mysqli_num_rows($r);
if($count == 1) {
// Create new hash
$key = hash('sha256', uniqid("", true));
// SQL query to update user record with hash value
$usql = "UPDATE registo set reset_key = '".$key."' where email = '".$email."'";
if(!mysqli_query($conn, $usql)) {
echo "Error updating database!";
}
// send link to user with generated key
$link="<a href='http://unn-w17015779.newnumyspace.co.uk/reset.php?key=".$key."'>Click To Reset password</a>";
$to = $email;
$subject = 'Reset Password';
$message = 'Click On This Link to Reset Password '.$link;
$headers = 'From: Galaxy books shop <**@gmail.com>' . "\r\n" .
'Reply-To: **@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// Send email
if(mail($to, $subject, $message, $headers)){
echo "Your reset link has been sent to your email ";
}else{
echo "Failed to Recover your password, try again";
}
} else {
echo "User name does not exist";
}
}
?>