5 @contact valerie@valware.co.uk
6 @description Provides support for PHPMailer() to send emails you care about
10 @icon https://w7.pngwing.com/pngs/78/575/png-transparent-phpmailer-hd-logo.png
14 use PHPMailer\PHPMailer\PHPMailer
;
15 use PHPMailer\PHPMailer\SMTP
;
19 public $name = "php_mailer";
20 public $author = "Valware";
21 public $version = "1.0";
22 public $description = "Send mail using PHPMailer()";
23 public $email = "v.a.pond@outlook.com";
25 function __construct()
27 Hook
::func(HOOKTYPE_USER_LOGIN
, 'php_mailer::user_login_notif');
28 Hook
::func(HOOKTYPE_USER_LOGIN_FAIL
, 'php_mailer::user_login_fail_notif');
31 public static function send_mail($to, $subject, $body)
33 $mail = new PHPMailer(true);
36 //$mail->SMTPDebug = 2;
37 $mail->isSMTP(); // Send using SMTP
38 $mail->Host
= get_config("smtp::host"); // Set the SMTP server to send through
39 $mail->SMTPAuth
= true; // Enable SMTP authentication
40 $mail->Username
= get_config("smtp::username"); // SMTP username
41 $mail->Password
= get_config("smtp::password"); // SMTP password
42 $mail->SMTPSecure
= get_config("smtp::encryption"); // Enable implicit TLS encryption
43 $mail->Port
= get_config("smtp::port"); // TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
46 $mail->setFrom(get_config("smtp::username"), get_config("smtp::from_name"));
47 $mail->addAddress($to['email'], $to['name']); // Add a recipient
50 $mail->isHTML(true); // Set email format to HTML
51 $mail->Subject
= $subject;
52 $mail->Body
= $body . "<br><br>Thank you for using UnrealIRCd!";
53 $mail->AltBody
= 'This is the body in plain text for non-HTML mail clients';
56 } catch (Exception
$e) {
57 die("Could not send mail:". $e);
62 * Send a login notification to the admin (note-to-self)
66 public static function user_login_notif($user)
69 ["email" => get_config("smtp::username"), "name" => get_config("smtp::from_name")],
70 "New login to Unreal Admin Panel",
71 "There was a new login to the admin panel.<br>User: \"$user->username\"<br>IP: \"".$_SERVER['REMOTE_ADDR']."\" (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>".
72 "User Agent: ".$_SERVER['HTTP_USER_AGENT']
77 ["email" => $user->email
, "name" => $user->first_name
. " " . $user->last_name
],
78 "New login to your account",
79 "Dear $user->first_name, <br><br>".
80 "There was a new login to account: \"$user->username\"<br><br>".
82 "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>".
83 "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>".
84 "If this was not you, please contact your Panel Administrator."
87 public static function user_login_fail_notif($fail)
90 ["email" => get_config("smtp::username"), "name" => get_config("smtp::from_name")],
91 "Failed login attempt - Unreal Admin Panel",
92 "There was a failed login attempt to the admin panel.<br>User: \"".$fail['login']."\"<br>IP: \"".$fail['IP']."\""
94 $user = new PanelUser($fail['login']);
97 ["email" => $user->email
, "name" => $user->first_name
. " " . $user->last_name
],
98 "Failed login attempt to your account",
99 "Dear $user->first_name, <br><br>".
100 "There was failed login attempt to your account: \"$user->username\"<br><br>".
102 "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>".
103 "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>".
104 "If this was not you, please contact your Panel Administrator."