-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendotp.php
65 lines (51 loc) · 2.24 KB
/
sendotp.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
<?php
session_start();
$con= new mysqli("localhost:3308","root","","virtual_police_station") or die(mysqli_error($con));
$email=$_POST['email'];
$res=mysqli_query($con,"SELECT email FROM `user` WHERE email='$email'") ;
$rows=mysqli_num_rows($res);
if($rows==0){
$otp=rand('11111','99999');
mysqli_query($con,"INSERT INTO `user` VALUES('$email','$otp')");
$_SESSION['email']=$email;
send_mail($otp);
echo "yes";
}
else{
$otp=rand('11111','99999');
mysqli_query($con,"UPDATE `user` set otp=$otp WHERE email='$email' ");
$_SESSION['email']=$email;
send_mail($otp);
echo "yes";
}
function send_mail($otp){
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'PKpandey@2000'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('[email protected]', 'VPS');
$mail->addAddress($_POST['email']); // Add a recipient
//$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'OTP VERIFICATION';
$mail->Body = 'OTP verification code is'.$otp.'</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
//echo 'Message could not be sent.';
//echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
//echo 'Message has been sent';
}
}
?>