-
Notifications
You must be signed in to change notification settings - Fork 1
/
Otp.php
125 lines (91 loc) · 3.62 KB
/
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="verification" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="otp.css">
<title>Document</title>
</head>
<body>
<div class="otpcls">
<form method="POST" action="verify.php">
<label for="otp">Enter OTP:</label>
<input type="text" id="otp" name="otp" required>
<!-- <input type="hidden" name="generatedOtp" value=""> -->
<br>
<button type="submit" name="submit">Verify OTP</button>
</form>
</div>
</body>
</html>
<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
session_start();
require "db_scripts/login.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloaderttyytytytytytyt
require 'PHPMailer\Exception.php';
require 'PHPMailer\PHPMailer.php';
require 'PHPMailer\SMTP.php';
function Redirect($url, $permanent = false)
{ //Redirects to given page
header('Location: ' . $url, true, $permanent ? 301 : 302);
exit();
}
$getemail = $_POST['useremail']; // user entered email
$emailfound = false;
//Checking if the email exists in the db
$tables = mysqli_query($conn, "SHOW TABLES");
while ($table_name = mysqli_fetch_object($tables)) {
$currentTable = $table_name->{"Tables_in_learn"};
$query = "SELECT * from $currentTable where Email = '$getemail'";
$results = mysqli_query($conn, $query);
if ($results->num_rows>0) {
$emailfound = true;
break;
}
}
if ($emailfound == true) {
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);
// SEND EMAIL PROCESS
try {
//Server settings
//Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = '[email protected]'; //SMTP username
$mail->Password = 'jlpwnvwpukyzjxpm'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('[email protected]', 'Contact Form');
$mail->addAddress($getemail, 'busx'); //Add a recipient
$random_number = '';
for ($i = 0; $i < 6; $i++) {
$random_number .= rand(0, 9);
}
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Busx authentication';
$mail->Body = 'Your <b>OTP Is : </b>' . '<strong>' . $random_number . '</strong>';
$_SESSION['generatedOTP'] = $random_number;
$_SESSION['usermail'] = $getemail;
$mail->send();
?>
<?php
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
} else {
?> <script>
alert("Please Enter Correct Email ! We Dont have any Bookings from this Email Please check your email .");
window.location.href ="GetOtp.html";
</script> <?php
// Redirect("GetOtp.html", false);
}
?>