-
Notifications
You must be signed in to change notification settings - Fork 1
/
mailforgot.php
95 lines (76 loc) · 2.52 KB
/
mailforgot.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
<?php
session_start();
if(isset($_POST['emailid']))
{
$email=$_POST["emailid"];
//echo $email;
$host="localhost"; //or the web server
$username="root";
$password="";
$database ="anand";
// Create connection
$conn = new mysqli($host, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die('Can\'t use' . DB_NAME . ':' . mysql_error());
}
$res = $conn->query("Select * from anand where emailid='$email'");
while($row=$res->fetch_assoc())
{
$uname=$row['myname'];
$upass=$row['mypass'];
$ustreet=$row['street'];
$ucity=$row['city'];
$ustate=$row['state'];
$upin=$row['pincode'];
//echo $uname." ".$upass;
}
//Load PHPMailer dependencies
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
/* CONFIGURATION */
$crendentials = array(
'email' => 'comps2017@gmail.com', //Your GMail adress
'password' => 'spcomps2017' //Your GMail password
);
/* SPECIFIC TO GMAIL SMTP */
$smtp = array(
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => $crendentials['email'],
'password' => $crendentials['password'],
'secure' => 'tls' //SSL or TLS
);
/* TO, SUBJECT, CONTENT */
$to = $_POST['emailid']; //The 'To' field
$subject = 'Forgotten Password';
$content = 'You forgot your password.<br>Your account details are:<br> You name is '.$uname." <br> Your password is ".$upass."<br>Your street is ".$ustreet."<br>Your city is ".$ucity."<br>Your state is ".$ustate."<br>Your pincode is ".$upin;
$mailer = new PHPMailer();
//SMTP Configuration
$mailer->isSMTP();
$mailer->SMTPAuth = true; //We need to authenticate
$mailer->Host = $smtp['host'];
$mailer->Port = $smtp['port'];
$mailer->Username = $smtp['username'];
$mailer->Password = $smtp['password'];
$mailer->SMTPSecure = $smtp['secure'];
//Now, send mail :
//From - To :
$mailer->From = $crendentials['email'];
$mailer->FromName = 'BALERI ENTERPRISES'; //Optional
$mailer->addAddress($to); // Add a recipient
//Subject - Body :
$mailer->Subject = $subject;
$mailer->Body = $content;
$mailer->isHTML(true); //Mail body contains HTML tags
header("Location:homepage.php");
//Check if mail is sent :
if(!$mailer->send()) {
echo 'Error sending mail : ' . $mailer->ErrorInfo;
} else {
header("Location:homepage.php");
//echo '<script>window.location.assign("login.php");</script>';
}
}
?>