-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemailscript.php
129 lines (103 loc) · 3.28 KB
/
emailscript.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
<?php
require_once('config.php');
error_reporting(E_ALL ^ E_NOTICE);
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$regno= clean($_POST['regno']);
//Input Validations
if($regno == '') {
$errmsg_arr[] = 'Please Enter Your Registration Number!';
$errflag = true;
}
//If there are wrong input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: studentforgotpwd.php");
exit();
}
if($regno != '')
{
$qry = "SELECT * FROM members WHERE regno='$regno' ";
$result = mysql_query($qry);
//Check if the reg no entered exists
if(mysql_num_rows($result)>0)
{
if(mysql_num_rows($result) == 1)
{
$queryy="SELECT * FROM members WHERE regno='$regno' ";
$resultt=mysql_query($queryy);
if(mysql_num_rows($resultt) == 1){
while($line=mysql_fetch_array($resultt ,MYSQL_ASSOC))
{
$f1=$line['login'];
$f2=$line['passwd'];
$f3=$line['email'];
}
}
}
}
else{
$errmsg_arr[] = 'Registration number duplication! Please contact administration to clear this error!';
$errflag = true;
}
}
/*email subject and and address*/
$emailSubject='Your Password and Username Details';
$emailAddress=$f3;
$kimathiemail='[email protected]';
/*gather data members*/
$body=<<<EOD
Usesrname: $f1</br>
Password: $f2<br />
EOD;
$headers="From: $kimathiemail\r\n";
$headers .="Content-type: text/html\r\n";
$success= mail($emailAddress, $emailSubject,$body,$headers);
$theResult=<<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration Successful</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
include('studentheaderinclude.php');
?>
<h1 class="notify">Process Successfull !!!</h1>
<p align="center">Your username and password details have been sent to the email address you registered with in this site</p>
<p align="center">Check your email and use the details to help you change your login password</p>
<p align="center">Please <a href="studentpwdfologin.php" >Click here</a> to use the details to change your password.</p>
</body>
</html>
EOD;
if($success){
echo "$theResult";
}
else {
die("Unable to connect to the internet right now, please make sure you are connected to the internet and try again ");
}
?>