-
Notifications
You must be signed in to change notification settings - Fork 0
/
forget.php
98 lines (74 loc) · 2.74 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
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
<html>
<html>
<head>
<font face="AR CHRISTY" color="black" size="150">Poodle.com</font>
<link href="style.css" rel="stylesheet">
</head>
<body>
<div id="heading"></div>
<nav id="nav01"></nav>
<div id="main">
<br><br><br><br><br>
<?php
require('PHPMailer-master/vendor/autoload.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$servername="localhost";
$username="admin";
$pass="monarchs"; //admin password
$db="userlog";
$connection =new mysqli($servername,$username,$pass,$db);
$email = $_POST['mail'];
$sql = "SELECT * FROM users WHERE email = '$email'";
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result) > 0)
{
$reset_token=md5($email);
}
else
{
echo "Email does not exists";
}
$sql = "UPDATE users SET reset_token='$reset_token' WHERE email='$email'";
mysqli_query($connection, $sql);
$message = "<p>Please click the link below to reset your password</p>";
$message .= "<a href='http://localhost/Poodle.com/setpassword.php?email=$email&reset_token=$reset_token'>";
$message .= "Reset password";
$message .= "</a>";
send_mail($email, "Reset password", $message);
function send_mail($to, $subject, $message)
{
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 0; // 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 = 'doodle4poodle*'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('[email protected]', 'Poodle.com');
//Recipients
$mail->addAddress($to);
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
echo 'Message has been sent. Please check your email for the reset password link.';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
$connection->close();
//mysqli_query($conn, "INSERT INTO `forget`(`mail`, `reset_token`) VALUES ( `$mail`,`$reset_token`)");
?>
<br><br><br><br><br><br>
</body>
<footer id="foot01"></footer>
</div>
<script src="script.js"></script>
</html>