%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64 User : ndkhermy ( 1200) PHP Version : 8.5.12 Disable Function : NONE Directory : /home1/ndkhermy/www/website_93b53270/ |
Upload File : |
<?php
include('header.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$website_name = $rows_website['website_name'];
// Start session if not already started
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if (isset($_POST['send_otp'])) {
$email = mysqli_real_escape_string($conn, $_POST['email']);
$loginQry = mysqli_query($conn, "SELECT * FROM `user_tbl` WHERE email='$email' AND type='User' AND status=1");
if (mysqli_num_rows($loginQry) > 0) {
$fet_user = mysqli_fetch_assoc($loginQry);
$user_name = $fet_user['name'] ?? 'User';
// Generate 4-digit OTP
$OTP = str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT);
// Update user with new OTP and token
$update_date = date('Y-m-d');
$token = 1;
mysqli_query($conn, "UPDATE `user_tbl`
SET `OTP`='$OTP', `update_date`='$update_date', `token`='$token'
WHERE email='$email' AND type='User' AND status=1");
// Fetch email configuration
$email_config = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM email_setting WHERE id=1"));
$host = $email_config['host'];
$port = $email_config['port'];
$username = $email_config['email'];
$password = $email_config['password'];
// Prepare email content
$email_temp = '
<h5>Hello ' . htmlspecialchars($user_name) . ',</h5>
<p>Your One-Time Password (OTP) for password recovery is given below. Please use this code to verify your account.
Do not share this code with anyone for security reasons.</p>
<table style="border: solid 2px #DDEEEE; border-collapse: collapse; font: normal 14px Roboto, sans-serif; margin: 15px 0;">
<thead>
<tr>
<th colspan="4" style="background-color: #DDEFEF; border: solid 1px #DDEEEE; color: #336B6B; padding: 10px; text-align: center;">
Your One-Time Password
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border: solid 1px #DDEEEE; color: #333; padding: 10px; text-align: center;">' . $OTP[0] . '</td>
<td style="border: solid 1px #DDEEEE; color: #333; padding: 10px; text-align: center;">' . $OTP[1] . '</td>
<td style="border: solid 1px #DDEEEE; color: #333; padding: 10px; text-align: center;">' . $OTP[2] . '</td>
<td style="border: solid 1px #DDEEEE; color: #333; padding: 10px; text-align: center;">' . $OTP[3] . '</td>
</tr>
</tbody>
</table>
<div>
<p style="font-size:12px;">Best Regards,<br>
<strong style="font-size:15px;color:red;">' . htmlspecialchars($website_name) . '</strong></p>
</div>';
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
// $mail->SMTPDebug = 2;
$mail->Host = $host;
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = $port;
$mail->setFrom($username, $website_name . ' | Forgot Password');
// $mail->addAddress($username);
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Subject = $website_name . ' : One Time Password';
$mail->Body = $email_temp;
if ($mail->send()) {
$_SESSION['message'] = 'OTP sent successfully to your email!';
$_SESSION['email'] = $email;
echo "<script>window.location='otp.php';</script>";
exit;
} else {
$_SESSION['error'] = 'Email sending failed. Please try again later.';
}
} catch (Exception $e) {
echo "Email could not be sent. Error: {$mail->ErrorInfo}";
}
// $mail->isSMTP();
// // $mail->SMTPDebug = 2;
// $mail->Host = $host;
// $mail->SMTPAuth = true;
// $mail->Username = $username;
// $mail->Password = $password;
// $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
// $mail->Port = $port;
// $mail->CharSet = 'UTF-8';
// $mail->setFrom($username, $website_name . ' | Forgot Password');
// // $mail->addAddress($username);
// $mail->addAddress($email);
// $mail->isHTML(true);
// $mail->Subject = $website_name . ' : One Time Password';
// $mail->Body = $email_temp;
// if ($mail->send()) {
// $_SESSION['message'] = 'OTP sent successfully to your email!';
// $_SESSION['email'] = $email;
// echo "<script>window.location='otp.php';</script>";
// exit;
// } else {
// $_SESSION['error'] = 'Email sending failed. Please try again later.';
// }
} else {
$_SESSION['error'] = 'This email is not registered!';
echo "<script>window.location='forgot-password.php';</script>";
exit;
}
}
?>
<style type="text/css">
.eye-icon {
float: right;
margin-right: 10px;
margin-top: -30px;
position: relative;
z-index: 99999;
}
</style>
<section id="login">
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3">
<div class="bg-grey m-5 p-4 rounded shadow-sm">
<?php if (isset($_SESSION['message'])): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong><?php echo $_SESSION['message']; ?></strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['message']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['error'])): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong><?php echo $_SESSION['error']; ?></strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
<form class="form-control p-4 border-0" method="POST" action="">
<h2 class="text-center text-danger mb-3">Forgot Password</h2>
<label>Email ID</label>
<input type="email" name="email" class="form-control" required placeholder="Enter your registered email">
<button type="submit" name="send_otp" class="btn btn-danger w-100 mt-3">Send OTP</button>
<div class="text-center mt-3">
<span>Back to <a class="text-danger text-decoration-none" href="<?=$base_url?>login.php">Login</a></span>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<?php include('footer.php'); ?>