-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforget-otp.php
61 lines (47 loc) · 1.46 KB
/
forget-otp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require_once('views/header.php');
if($_SESSION['validate'] != "enter-email"){
header('Location:enter-email.php');
}
$_SESSION['validate'] = "forget-otp";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
//Start session
//session_start();
$email =$_SESSION['email'];
// Generate an OTP code
$otp = mt_rand(100000, 999999);
// Create a new PHPMailer object
$mail = new PHPMailer();
// Set the SMTP settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'aqsdnbtxmkyqqjah';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Set the email content
$mail->setFrom('[email protected]', 'OWMS');
$mail->addAddress($email);
$mail->Subject = 'Your OTP code';
$mail->Body = 'Your OTP code is: ' . $otp;
// Send the email
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
// Store the OTP code in the database
$stmt = mysqli_prepare($conn, "UPDATE user SET otp = '".$otp."' WHERE email = '".$email."'");
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($conn);
// Redirect to the OTP verification page
$_SESSION['email']= $email;
header('Location:enterforget-otp.php');
// header('Location: otpverify.php?email=' . urlencode($email));
exit;
}
?>