-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckEmail.php
More file actions
66 lines (52 loc) · 1.79 KB
/
checkEmail.php
File metadata and controls
66 lines (52 loc) · 1.79 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
58
59
60
61
62
63
64
65
66
<?php
header("Content-type:application/json");
$_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded";
error_reporting (E_ALL ^ E_WARNING && E_NOTICE);
//response class
class CheckEmailResponse {
var $idFound;
var $emailSent;
function __construct () {
$idFound = false;
$emailSent = false;
}
}
//Connection properties
$servername = "localhost";
$username = "root";
$password = "admin";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Extract id and password from GET
$userID = $_POST["userID"];
//Run query for login authorization
$checkEmailQuery = "SELECT * FROM db_classroom_management.tbl_login_accounts where account_id=".$userID;
$checkEmailQueryResult = mysqli_query($conn, $checkEmailQuery);
//Handle login authorization response
$numberOfRows = mysqli_num_rows($checkEmailQueryResult);
$response = new CheckEmailResponse();
if ($numberOfRows == 1) {
$row = mysqli_fetch_assoc($checkEmailQueryResult);
$response->idFound = true;
//Email Sending
$to = $row["email_address"];
$subject = "You requested the password for your account.";
$message = "Hello Sir/Miss! \r\n";
$message .= "Your account id is " . $userID . "\nYour Password is " . $row["password"] . "\r\n";
$message .= "Kind Regards.";
$header = "From:fypAreebaSabaZareen@hamdard.edu.pk\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
$response->emailSent = true;
}
} else if ($numberOfRows == 0) {
$response->idFound = false;
}
echo json_encode($response);
?>