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
= EMAIL_SETTINGS
['host']; //Set the SMTP server to send through
28 $mail->SMTPAuth
= true; //Enable SMTP authentication
29 $mail->Username
= EMAIL_SETTINGS
['username']; //SMTP username
30 $mail->Password
= EMAIL_SETTINGS
['password']; //SMTP password
31 $mail->SMTPSecure
= EMAIL_SETTINGS
['encryption']; //Enable implicit TLS encryption
32 $mail->Port
= EMAIL_SETTINGS
['port']; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
35 $mail->setFrom(EMAIL_SETTINGS
['username'], EMAIL_SETTINGS
['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" => EMAIL_SETTINGS
['username'], "name" => EMAIL_SETTINGS
['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']."\""
65 ["email" => $user->email
, "name" => $user->first_name
. " " . $user->last_name
],
66 "New login to your account",
67 "Dear $user->first_name, <br><br>".
68 "There was a new login to account: \"$user->username\"<br><br>".
70 "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>".
71 "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>".
72 "If this was not you, please contact your Panel Administrator."
75 public static function user_login_fail_notif($fail)
78 ["email" => EMAIL_SETTINGS
['username'], "name" => EMAIL_SETTINGS
['from_name']],
79 "Failed login attempt - Unreal Admin Panel",
80 "There was a failed login attempt to the admin panel.<br>User: \"".$fail['login']."\"<br>IP: \"".$fail['IP']."\""
82 $user = new PanelUser($fail['login']);
85 ["email" => $user->email
, "name" => $user->first_name
. " " . $user->last_name
],
86 "Failed login attempt to your account",
87 "Dear $user->first_name, <br><br>".
88 "There was failed login attempt to your account: \"$user->username\"<br><br>".
90 "IP: ".$_SERVER['REMOTE_ADDR']." (".$_SERVER['HTTP_CF_IPCOUNTRY'].")<br>".
91 "User Agent: ".$_SERVER['HTTP_USER_AGENT']."<br><br>".
92 "If this was not you, please contact your Panel Administrator."