-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_reset.php
More file actions
51 lines (31 loc) · 1.13 KB
/
Copy pathsend_reset.php
File metadata and controls
51 lines (31 loc) · 1.13 KB
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
<?php
$email = $_POST['email'];
$token = bin2hex(random_bytes(16));
$token_hash = hash("sha256", $token);
$expiry = date("Y-m-d H:i:s", time() + 60 * 30);
require "dbcon.php";
$sql = "UPDATE student_registration
SET reset_token = ?,
token_expires = ?
WHERE email = ?";
$stmt = $conn->prepare ($sql);
$stmt->bind_param ("sss", $token_hash, $expiry, $email);
$stmt->execute();
if ($conn->affected_rows) {
$mail = require "mailer.php";
$mail->setFrom("noreply@example.com");
$mail->addAddress($email);
$mail->Subject = 'Password Reset Link From Admin Panel';
$mail->Body = "We have got a request from you to reset your password!<br>
Click the link below:<br>
<a href='http://localhost/php_mail/reset-password.php?token=$token'>Reset Password</a>";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
// END;
try {
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer error: {$mail->ErrorInfo}";
}
}
echo "Message sent, please check your inbox.";
?>