Hi Team
I dont have errors i have debugged the application, basically what i am trying to do. When before submiting a form, the form should hold until a user receive an email has an otp, so that can insert and continue. Problem i am experience i am not receiving an email.Maybe its something i am missing, setup everything from the phpmailer because it is working for registering users to the site.
// forgot-password.php
// otp-confirmation.php
prepare($sql);
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
// Generate a random OTP and store it in the session
$otp = rand(100000, 999999);
$_SESSION['otp'] = $otp;
$_SESSION['email'] = $email;
// Send an email to the user with the OTP
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.outlook.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = '***';
$mail->setFrom('[email protected]', 'Your Name');
$mail->addAddress($email);
$mail->Subject = 'Password reset OTP';
$mail->Body = 'Dear user,
Your OTP to reset your password is: ' . $otp;
$mail->AltBody = 'Dear user, your OTP to reset your password is: ' . $otp;
$mail->isHTML(true);
if (!$mail->send()) {
$error = 'Error: ' . $mail->ErrorInfo;
} else {
// Redirect the user to the OTP verification page
header("Location: verify_otp.php");
exit();
}
} else {
// If the email does not exist in the database, display an error message
$error = "Email not found. Please try again.";
}
}
?>
Rajkiran SwainPosted May 6, 2023, 1:59 PM
It seems like you are trying to implement a forgot password functionality that sends an OTP to the user's email address for verification. However, it seems like the email is not being received by the user.
There could be several reasons why the email is not being received:
The email could be getting filtered as spam by the email provider. Make sure to check the spam folder of the email account.
The SMTP settings might not be configured correctly. Double-check the SMTP settings, including the hostname, port, and authentication details.
The email address might not be valid. Make sure to check that the email address is correct and without any typos.
The email might not be sent due to an error in the PHP code. Make sure to check that the PHP code is correct and there are no errors.
To debug the issue, you can try the following steps:
Check the spam folder of the email account.
Check the SMTP settings, including the hostname, port, and authentication details.
Try sending an email manually to the same email address using the same SMTP settings and see if it is received.
Check the PHP code for any errors or syntax issues.
Also, make sure to test the functionality on different email providers to ensure that the issue is not specific to a particular email provider.