-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgot_password_process.php
More file actions
57 lines (51 loc) · 2.45 KB
/
forgot_password_process.php
File metadata and controls
57 lines (51 loc) · 2.45 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
52
53
54
55
56
57
<?php
if(isset($_POST['reset'])) {
$email = $_POST['email'];
}
else {
exit();
}
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'mail/Exception.php';
require 'mail/PHPMailer.php';
require 'mail/SMTP.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$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 = 'wrapifygiftshop203@gmail.com'; // SMTP username
$mail->Password = 'sibuolevtjnypvcy'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('wrapifygiftshop203@gmail.com', 'Wrapify');
$mail->addAddress($email); // Add a recipient
$code = substr(str_shuffle('1234567890QWERTYUIOPASDFGHJKLZXCVBNM'),0,10);
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Password Reset';
$mail->Body = 'To reset your password click <a href="http://localhost/wrapify/changepassword1.php?code='.$code.'">here </a>. </br>Reset your password in a day.';
$conn = new mySqli('127.0.0.1', 'root', '', 'giftshopphp');
if($conn->connect_error) {
die('Could not connect to the database.');
}
$verifyQuery = $conn->query("SELECT * FROM siteuser WHERE emailid = '$email'");
if($verifyQuery->num_rows) {
$codeQuery = $conn->query("UPDATE siteuser SET code = '$code' WHERE emailid = '$email'");
$mail->send();
echo 'Message has been sent, check your email';
}
else
{
echo "Please First Sign Up !!";
}
$conn->close();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>