3 use PHPMailer\PHPMailer\PHPMailer
;
4 use PHPMailer\PHPMailer\SMTP
;
8 public $name = "PHPMailer()";
9 public $author = "Valware";
10 public $version = "1.0";
11 public $description = "Send mail using PHPMailer()";
12 public $email = "v.a.pond@outlook.com";
14 function __construct()
16 Hook
::func(HOOKTYPE_USER_LOGIN
, 'php_mailer::user_login_notif');
17 Hook
::func(HOOKTYPE_USER_LOGIN_FAIL
, 'php_mailer::user_login_fail_notif');
20 public static function send_mail($to, $subject, $body)
22 $mail = new PHPMailer(true);
25 //$mail->SMTPDebug = 2;
26 $mail->isSMTP(); // Send using SMTP
27 $mail->Host
= get_config("smtp::host"); // Set the SMTP server to send through
28 $mail->SMTPAuth
= true; // Enable SMTP authentication
29 $mail->Username
= get_config("smtp::username"); // SMTP username
30 $mail->Password
= get_config("smtp::password"); // SMTP password
31 $mail->SMTPSecure
= get_config("smtp::encryption"); // Enable implicit TLS encryption
32 $mail->Port
= get_config("smtp::port"); // TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
35 $mail->setFrom(get_config("smtp::username"), get_config("smtp::from_name"));
36 $mail->addAddress($to['email'], $to['name']); // Add a recipient
39 $mail->isHTML(true); // Set email format to HTML
40 $mail->Subject
= $subject;
41 $mail->Body
= $body . "<br><br>Thank you for using UnrealIRCd!";
42 $mail->AltBody
= 'This is the body in plain text for non-HTML mail clients';
45 } catch (Exception
$e) {
46 die("Could not send mail:". $e);
51 * Send a login notification to the admin (note-to-self)
55 public static function user_login_notif($user)
58 ["email" => get_config("smtp::username"), "name" => get_config("smtp::from_name")],
59 "New login to Unreal Admin Panel",
60 "There was a new login to the admin panel.<br>User: \"$user->username\"<br>IP: \"".$_SERVER['REMOTE_ADDR']."\" (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>".
61 "User Agent: ".$_SERVER['HTTP_USER_AGENT']
66 ["email" => $user->email
, "name" => $user->first_name
. " " . $user->last_name
],
67 "New login to your account",
68 "Dear $user->first_name, <br><br>".
69 "There was a new login to account: \"$user->username\"<br><br>".
71 "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>".
72 "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>".
73 "If this was not you, please contact your Panel Administrator."
76 public static function user_login_fail_notif($fail)
79 ["email" => get_config("smtp::username"), "name" => get_config("smtp::from_name")],
80 "Failed login attempt - Unreal Admin Panel",
81 "There was a failed login attempt to the admin panel.<br>User: \"".$fail['login']."\"<br>IP: \"".$fail['IP']."\""
83 $user = new PanelUser($fail['login']);
86 ["email" => $user->email
, "name" => $user->first_name
. " " . $user->last_name
],
87 "Failed login attempt to your account",
88 "Dear $user->first_name, <br><br>".
89 "There was failed login attempt to your account: \"$user->username\"<br><br>".
91 "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>".
92 "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>".
93 "If this was not you, please contact your Panel Administrator."