]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - plugins/php_mailer/php_mailer.php
Plugins list: change wording to 'installed' instead of 'available'
[irc/unrealircd/unrealircd-webpanel.git] / plugins / php_mailer / php_mailer.php
CommitLineData
c44f6efa
VP
1<?php
2
3use PHPMailer\PHPMailer\PHPMailer;
4use PHPMailer\PHPMailer\SMTP;
5
6class php_mailer
7{
8 public $name = "PHPMailer()";
9 public $author = "Valware";
10 public $version = "1.0";
11 public $description = "Send mail using PHPMailer()";
b65f0496 12 public $email = "v.a.pond@outlook.com";
c44f6efa
VP
13
14 function __construct()
15 {
16 Hook::func(HOOKTYPE_USER_LOGIN, 'php_mailer::user_login_notif');
17 Hook::func(HOOKTYPE_USER_LOGIN_FAIL, 'php_mailer::user_login_fail_notif');
18 }
19
20 public static function send_mail($to, $subject, $body)
21 {
22 $mail = new PHPMailer(true);
23 try {
24 //Server settings
25 //$mail->SMTPDebug = 2;
135ba4d7
BM
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`
c44f6efa
VP
33
34 //Recipients
135ba4d7
BM
35 $mail->setFrom(get_config("smtp::username"), get_config("smtp::from_name"));
36 $mail->addAddress($to['email'], $to['name']); // Add a recipient
c44f6efa
VP
37
38 //Content
135ba4d7 39 $mail->isHTML(true); // Set email format to HTML
c44f6efa
VP
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';
43
44 $mail->send();
c44f6efa 45 } catch (Exception $e) {
b65f0496 46 die("Could not send mail:". $e);
c44f6efa
VP
47 }
48 }
49
50 /**
51 * Send a login notification to the admin (note-to-self)
52 * @param mixed $user
53 * @return void
54 */
55 public static function user_login_notif($user)
56 {
57 self::send_mail(
135ba4d7 58 ["email" => get_config("smtp::username"), "name" => get_config("smtp::from_name")],
c44f6efa 59 "New login to Unreal Admin Panel",
226d9858
VP
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']
c44f6efa 62 );
3231a11b
VP
63
64 if ($user->email)
65 self::send_mail(
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>".
70 "Details:<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."
74 );
c44f6efa
VP
75 }
76 public static function user_login_fail_notif($fail)
77 {
78 self::send_mail(
135ba4d7 79 ["email" => get_config("smtp::username"), "name" => get_config("smtp::from_name")],
c44f6efa
VP
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']."\""
82 );
3231a11b
VP
83 $user = new PanelUser($fail['login']);
84 if ($user->email)
85 self::send_mail(
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>".
90 "Details:<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."
94 );
c44f6efa
VP
95 }
96}