-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample SMTP 1.php
138 lines (107 loc) · 4.28 KB
/
sample SMTP 1.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
require("PHPMailer/PHPMailerAutoload.php");
session_start();
include('connection.php');
$usn=mysql_real_escape_string($_POST['user']);
$email=mysql_real_escape_string($_POST['email']);
function generateRandomString($length = 10)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++)
{
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$str1=generateRandomString();
$query=mysql_query("SELECT * FROM stu_personal where USN='$usn' and email_id='$email'");
$query1=mysql_fetch_assoc($query);
if(!$query1)
{
echo "<script type='text/javascript'>alert('no such entry in the database either USN or emailID doesnot match')</script>";
echo "<script type='text/javascript'>window.location.href= 'student_forgot.html';</script>";
}
else
{
$ins=mysql_query("UPDATE stu_personal SET password='$str1' WHERE USN='$usn'");
if(!$ins)
{
//echo "<script type='text/javascript'>alert('try again!!')</script>";
//echo "<script type='text/javascript'>window.location.href= 'testing_studenthtml.html';</script>";
die(mysql_error());
}
$name=$query1['name'];
$pass = $str1;//FETCHING PASS
$to = $email;
$body = "<b>Hello ".$name." your new password for the account is: </br>
</br>".$pass;
/*$from = "[email protected]";
$subject = "Password recovery";
$headers1 = "From: $from\n";
$headers1 .= "Content-type: text/html;charset=iso-8859-1\r\n";
$headers1 .= "X-Priority: 1\r\n";
$headers1 .= "X-MSMail-Priority: High\r\n";
$headers
1 .= "X-Mailer: Just My Server\r\n";
$sentmail = mail ( $to, $subject, $body, $headers1 );*/
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server for gmail
$Mail->SMTPDebug = 0; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port to gmail's port
$Mail->Username = 'pesrupam'; // gmail account username
$Mail->Password = 'pesrupam123'; // gmail account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Password Recovery';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = '[email protected]'; //Your email adress (Gmail overwrites it anyway)
$Mail->FromName = 'rupam';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->addAddress($to); // To
$Mail->isHTML( TRUE );
$Mail->Body = $body;
$Mail->AltBody = 'This is a recovery mail';
//$_SESSION['user1'] = $row;
if(!$Mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $Mail->ErrorInfo;
exit;
}
$Mail->SmtpClose();
echo "<script type='text/javascript'>alert(' new password for login sent to registered e-mail Id')</script>";
echo "<script type='text/javascript'>window.location.href= 'studentlogin.html';</script>";
}
//}
//else {
//echo "<span style='color:#ff0000;'> Not found your email in our database</span>";
//}
//If the message is sent successfully, display sucess message otherwise display an error message.
//}
//mysql_query("INSERT INTO stu_education(USN) VALUES ('$usn')");
//mysql_query("INSERT INTO stu_personal((name,father's_name,dob,temporary_address,permanent_address,email_id,mobile,landline) VALUES('$name','$father','$dob','$taddr','$paddr','$email','$mob','$land') where USN='$usn'");
//to check if an actual image or fake image
/*if(isset($_POST['upload']) && $_FILES['attach']['size'] > 0)
{
$fileName = $_FILES['attach']['name'];
$tmpName = $_FILES['attach']['tmp_name'];
$fileSize = $_FILES['attach']['size'];
$fileType = $_FILES['attach']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
$ins =mysql_query("UPDATE notification SET file_name='$fileName',file_type='$fileType',file_size='$fileSize',file_content='$content' where nid=1");
*/
?>