-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_forget.php
143 lines (99 loc) · 3.63 KB
/
edit_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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
session_start();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$con =mysqli_connect('localhost','root','');
mysqli_select_db($con ,'signup');
$email=$_POST['email_id'];
$s ="SELECT * FROM usersignup WHERE email_id = '$email'";
$result =mysqli_query($con ,$s);
$num = mysqli_num_rows($result);
if($num == 1)
{
if (isset($_POST["email_id"])) {
// Instantiation and passing `true` enables exceptions
$email= $_POST['email_id'];
$code=uniqid(true);
$m ="INSERT INTO resetpassword(code ,email_id) VALUES('$code','$email')";
$r1=mysqli_query($con ,$m);
if (!$r1) {
exit("Error");
}
$mail = new PHPMailer(true);
try {
$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 = 'Vgec_hostel0101'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('[email protected]', 'Hello');
$mail->addAddress($email); // Add a recipient
$mail->addReplyTo('[email protected]', 'No reply');
// Content
$url = "http://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["PHP_SELF"]) ."/resetpassword.php?code=$code";
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Your password reset link';
$mail->Body = "<h1>You requested for reset password</h1>
click <a href='$url'>this link</a> to do so<br>code:$code";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo "<script> alert('Reset password link has been sent to your email address');</script>";
}
catch (Exception $e)
{
echo "<script> alert('Message could not be sent.');</script> Mailer Error: {$mail->ErrorInfo}";
}
}
}
else
{
echo "<script> alert('enter valid email'); </script>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.card {
box-shadow: 0 8px 8px 0 rgba(0,0,0,0.5);
transition: 0.6s;
width: 600px;
height: 400px;
border-radius: 8px;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(43, 105, 100, 1)
}
</style>
</head>
<body>
<div class="card">
<form method="POST" action="forget.php">
<div>
<input type="email" class="form-control" name="email_id" placeholder="Email address" required="required">
<span class="focus-input"></span>
</div>
<div class="form-group">
<button class="btn btn-lg btn-primary btn-block" type="submit" >Recover your password</button>
</div>
</form>
</div>
</div>
</body>
</html>