-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeEmail.php
67 lines (59 loc) · 2.65 KB
/
CodeEmail.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
<?php
session_start();
include('DbConnection.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
if (isset($_POST['send_otp_btn'])){
$email = $_POST['email'];
$sql = "SELECT * FROM users WHERE email = '$email'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
if($count>0){
$randomNumber = rand(100000, 999999);
$_SESSION['otp']=$randomNumber;
sendemail_verify("$email","$randomNumber");
$_SESSION['status']="OTP sent successfully";
$_SESSION['email']=$email;
header("location:VerificationCode.php");
}
else{
$_SESSION['status']="User not found.Please enter valid email or create an new account.";
header('location:EnterEmail.php');
}
}
function sendemail_verify($email,$randomNumber){
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/Exception.php';
require 'PHPMailer/SMTP.php';
$mail = new PHPMailer(true);
try {
//Server settings
$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 = 'iitspl89@gmail.com'; //SMTP username
$mail->Password = 'yywtcjssestdopzb'; //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('iitspl89@gmail.com', 'Mailer');
$mail->addAddress($email); //Add a recipient
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'OTP';
$email_template="
<h2>Hello, You have requested for password reset in Sign Language Detection System</h2>
<br />
<h2>Use this OTP get verified : {$randomNumber}</h2>
<br/>
";
$mail->Body = $email_template;
$mail->send();
return true;
} catch (Exception $e) {
return false;
// echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>