]> jfr.im git - irc/unrealircd/unrealircd-webpanel-plugins.git/blob - php_mailer/php_mailer.php
Update php_mailer.php
[irc/unrealircd/unrealircd-webpanel-plugins.git] / php_mailer / php_mailer.php
1 <?php
2 /**
3 @title PHP Mailer
4 @author Valware
5 @contact valerie@valware.co.uk
6 @description Provides support for PHPMailer() to send emails you care about
7 @version 1.0
8 @tested 1.0
9 @minver 1.0
10 @icon https://w7.pngwing.com/pngs/78/575/png-transparent-phpmailer-hd-logo.png
11 @maxver *
12 @license GPLv3
13 */
14 use PHPMailer\PHPMailer\PHPMailer;
15 use PHPMailer\PHPMailer\SMTP;
16
17 class php_mailer
18 {
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";
24
25 function __construct()
26 {
27 Hook::func(HOOKTYPE_USER_LOGIN, 'php_mailer::user_login_notif');
28 Hook::func(HOOKTYPE_USER_LOGIN_FAIL, 'php_mailer::user_login_fail_notif');
29 }
30
31 public static function send_mail($to, $subject, $body)
32 {
33 $mail = new PHPMailer(true);
34 try {
35 //Server settings
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`
44
45 //Recipients
46 $mail->setFrom(get_config("smtp::username"), get_config("smtp::from_name"));
47 $mail->addAddress($to['email'], $to['name']); // Add a recipient
48
49 //Content
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';
54
55 $mail->send();
56 } catch (Exception $e) {
57 die("Could not send mail:". $e);
58 }
59 }
60
61 /**
62 * Send a login notification to the admin (note-to-self)
63 * @param mixed $user
64 * @return void
65 */
66 public static function user_login_notif($user)
67 {
68 self::send_mail(
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']
73 );
74
75 if ($user->email)
76 self::send_mail(
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>".
81 "Details:<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."
85 );
86 }
87 public static function user_login_fail_notif($fail)
88 {
89 self::send_mail(
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']."\""
93 );
94 $user = new PanelUser($fail['login']);
95 if ($user->email)
96 self::send_mail(
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>".
101 "Details:<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."
105 );
106 }
107 }