-
Notifications
You must be signed in to change notification settings - Fork 14
/
send_otp.php
49 lines (40 loc) · 1.25 KB
/
send_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
<?php
session_start();
require('database/DBController.php');
$db = new DBController();
$email = mysqli_real_escape_string($db->con, $_POST['email']);
$query = "INSERT INTO `users` (`email`) VALUES ('$email')";
$result = mysqli_query($db->con,$query);
$otp = rand(111111,999999);
mysqli_query($db->con, "UPDATE `users` set `otp`='$otp' where `email` = '$email'");
$htmldata = 'Hi, <br> You are just a step away from accessing your Flipkart Clone account <br><br> Your OTP for Flipkart Clone is : <h3>'.$otp.'</h3>';
smtp_mailer($email,'Your OTP for Email Verification',$htmldata);
echo "mailed";
$_SESSION['EMAIL'] = $email;
// echo $email;
function smtp_mailer($to,$subject,$msg){
require_once("phpmailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
// $mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Username = "[email protected]";
$mail->Password = "jhonDoe#11";
$mail->SetFrom("[email protected]","Fipkart Clone");
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->AddAddress($to);
if(!$mail->Send()){
return 0;
// echo $mail->ErrorInfo;
// echo "yes";
}else{
return 1;
}
}
?>