-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgot.php
106 lines (86 loc) · 3.57 KB
/
forgot.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
<?php
/* Reset your password form, sends reset.php password link */
require 'db.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/Exception.php';
require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';
session_start();
// Check if form submitted with method="post"
if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
$email = $mysqli->escape_string($_POST['email']);
$result = $mysqli->query("SELECT * FROM users WHERE email='$email'");
if ( $result->num_rows == 0 ) // User doesn't exist
{
$_SESSION['message'] = "User with that email doesn't exist!";
header("location: error.php");
}
else { // User exists (num_rows != 0)
$user = $result->fetch_assoc(); // $user becomes array with user data
$email = $user['email'];
$hash = $user['hash'];
$username = $user['username'];
// Session message to display on success.php
$_SESSION['message'] = "<p>Please check your email <span>$email</span>"
. " for a confirmation link to complete your password reset!</p>";
// Send registration confirmation link (reset.php)
// Send registration confirmation link (verify.php)
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $mail_host; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'donotreply@fantasy-sim.com'; // SMTP username
$mail->Password = $mail_pass_donotreply; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect
//Recipients
$mail->setFrom('donotreply@fantasy-sim.com', 'Mailer');
$mail->addAddress($email); // Name is optional
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Account Verification ( fantasy-sim.com )';
$mail->Body = '
Hello '.$username.',
You have requested password reset!
Please click this link to reset your password:
http://fantasy-sim.com/reset.php?email='.$email.'&hash='.$hash;
$mail->send();
echo 'Message has been sent';
//header("location: home.php");
echo "<script>window.location.replace = 'success.php'</script>";
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
//header("location: home.php");
echo "<script>window.location.replace = 'home.php'</script>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Reset Your Password</title>
<?php include 'css/css.html'; ?>
</head>
<body>
<div class="form">
<h1>Reset Your Password</h1>
<form action="forgot.php" method="post">
<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input type="email"required autocomplete="off" name="email"/>
</div>
<button class="button button-block"/>Reset</button>
</form>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>