forked from Git21221/IBMSkillsBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForget.php
60 lines (40 loc) · 2.17 KB
/
Forget.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
<?php
session_start();
include_once 'db.php';
$email = $_POST['email'];
if( !empty($email)){
if(filter_var($email,FILTER_VALIDATE_EMAIL)){
$sql = mysqli_query($conn,"SELECT email FROM elitte WHERE email = '{$email}'");
if(mysqli_num_rows($sql)>0){
$random_id = rand(time(),10000000);
$otp = mt_rand(1111,9999);
$sql2 = mysqli_query($conn,"UPDATE elitte SET `otp`='$otp' WHERE email='{$email}'");
$sql3= mysqli_query($conn , "SELECT * FROM elitte WHERE email = '{$email}'");
if(mysqli_num_rows($sql3)>0){
$row = mysqli_fetch_assoc($sql3);
$_SESSION['email']=$row['email'];
$_SESSION['otp']=$row['otp'];
if($otp){
$to = $email;
$subject = "Verify Your Email";
$body = "Your Verification code to reset password is"." $otp";
$headers = "From: noreply@gmail.com";
$mail_sent =mail($to, $subject, $body, $headers);
if($mail_sent==true){
echo "success";
}
else{
echo "Email Problem!" . mysqli_error($conn);
}
}
}
}
else{
echo "$email ~ Not Exists";
}
}
}
else{
echo "All Input Fields are Required";
}
?>