-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.php
144 lines (114 loc) · 5.07 KB
/
mailer.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
139
140
141
142
143
144
<?php
include("conn.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/PHPMailer/src/Exception.php';
require 'vendor/PHPMailer/src/PHPMailer.php';
require 'vendor/PHPMailer/src/SMTP.php';
session_start();
if (isset($_POST['send'])) {
$email = $_POST['email'];
$subject = $_POST['subject'];
$random_base64 = uniqid();
$dir = __DIR__;
$root = "";
$dir = str_replace('\\', '/', realpath($dir));
//HTTPS or HTTP
$root .= !empty($_SERVER['HTTPS']) ? 'https' : 'http';
//HOST
$root .= '://' . $_SERVER['HTTP_HOST'];
//ALIAS
if (!empty($_SERVER['CONTEXT_PREFIX'])) {
$root .= $_SERVER['CONTEXT_PREFIX'];
$root .= substr($dir, strlen($_SERVER['CONTEXT_DOCUMENT_ROOT']));
} else {
$root .= substr($dir, strlen($_SERVER['DOCUMENT_ROOT']));
}
$root .= '/';
// Hi sindewesley5,
// Someone has requested a new password for the following account on DashboardPack:
// Username: sindewesley5
// If you didn't make this request, just ignore this email. If you'd like to proceed:
// Click here to reset your password
// Thanks for reading.
//echo $root ;
$username = strstr($email, '@', true); //"username"
$MyUkey = 'passWordReset.php?u_key=' . $random_base64;
$yourLink = "<a href=" . $root . $MyUkey . "> Click Here!!! </a>";
$message = "<tr></td><td ><h2><font color = #346699>Hi " . $username . "\r\n" .
"</font><h2></td></tr>Someone has requested a new password for the following account on <b>Topmax</b>
If you didn't make this request, just ignore this email.\r If you'd like to proceed:
You can reset your account using the following Link 👇 to reset your password
<tr></td><td ><h2><font color = #171c21>Thanks for reading.</font><h2></td></tr>
<tr></td><td ><h2><font color = #346699>" . $yourLink . "</font><h2></td></tr>";
// $selAcc = $conn->query("SELECT * FROM examinee_tbl WHERE Reg_No='$username' ");
// $selAccRow = $selAcc->fetch(PDO::FETCH_ASSOC);
// if ($selAcc->rowCount() > 0) {
$selExmneeData = $conn->query("SELECT * FROM examinee_tbl WHERE exmne_email='$email ' ");
$selAccRow = $selExmneeData->fetch(PDO::FETCH_ASSOC);
if ($selExmneeData->rowCount() > 0) {
$exmnId = $selAccRow['exmne_id'];
$insertDAta = $conn->query("INSERT into passreset (u_id, u_key) VALUES ('$exmnId','$random_base64')");
//Load composer's autoloader
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = '**********';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
//Send Email
$mail->setFrom('[email protected]');
//Recipients
$mail->addAddress($email);
$mail->addReplyTo('[email protected]');
$imgs = $root . "images/topmax.png";
//Content
$mail->isHTML(true);
$headers = "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= 'From: Topmax College' . "\r\n";
$body = "<table width=100% border=0><tr><td>";
$body .= "'</td><td style=position:absolute;left:50;top:60;><h2 background-color=#4d1c4f><font color = #346699>TOPMAX COLLEGE.</font><h2></td></tr>";
//$Body .= $message;
$mail->Subject = $subject;
$mail->Body = $body . $message; // = $message;
$mail->headers = $headers;
$mail->send();
$_SESSION['result'] = 'Message has been sent to your email. Check on your email on how to reset password';
$_SESSION['status'] = 'ok';
//echo 'Message has been sent to your email. Check on your email on how to reset password';
function imageUrl()
{
return "http://" . $_SERVER['SERVER_NAME'] . substr(
$_SERVER['SCRIPT_NAME'],
0,
strrpos($_SERVER['SCRIPT_NAME'], "/") + 1
) . "images/topmax.png";
}
} catch (Exception $e) {
$_SESSION['result'] = 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
$_SESSION['status'] = 'error';
//echo 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}
} else {
$_SESSION['result'] = 'No email was fount related to this account, ENTER CORRECT EMAIL. System Error: ';
$_SESSION['status'] = 'error';
//echo 'No email was fount related to this account, ENTER CORRECT EMAIL. System Error: ' . $email;
}
}
header("location: forgotPassword.php");
$_SESSION['try'] = $random_base64;;
?>
<script>
alert(<?php echo $MyUkey; ?>)
</script>