PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Notification / Email.php
backup / src / JetBackup / Notification Last commit date
.htaccess 1 year ago Email.php 1 year ago Notification.php 1 year ago index.html 1 year ago web.config 1 year ago
Email.php
64 lines
1 <?php
2
3 namespace JetBackup\Notification;
4
5 use JetBackup\Exception\NotificationException;
6 use JetBackup\Factory;
7 use JetBackup\Wordpress\Helper;
8 use JetBackup\Wordpress\Wordpress;
9
10 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
11
12 class Email {
13
14 private function __construct() {}
15
16 /**
17 * @throws NotificationException
18 */
19 public static function send($recipient, $subject, $message, $attachments=[], $from=null, $headers=[]) {
20
21
22 if (!Factory::getSettingsNotifications()->isEmailsEnabled()) return true; // Do nothing if emails are disabled
23 if (!Helper::validateEmail($recipient)) throw new NotificationException("Email recipient ($recipient) invalid!");
24
25
26
27 if(!$from) {
28 $site_url = parse_url(Wordpress::getBlogInfo('url'));
29 // Use a fake domain if running on localhost (real domains may be rejected in tests)
30 $from = 'wordpress@' . ($site_url['host'] === 'localhost' ? 'localhost.local' : $site_url['host']);
31 }
32
33 if(!$recipient) {
34 $recipient = Wordpress::getBlogInfo('admin_email');
35 }
36
37 if (!Helper::validateEmail($from)) throw new NotificationException("Email from ($from) invalid!");
38
39 $subject = Wordpress::sanitizeTextField($subject);
40
41 $headers = array_merge($headers, [
42 'MIME-Version: 1.0',
43 'Content-Type: text/html; charset=UTF-8',
44 ]);
45
46 foreach ($headers as $key => $value) {
47 $headers[$key] = Wordpress::sanitizeTextField($value);
48 }
49
50 // Ensure $attachments is an array
51 $attachments = is_array($attachments) ? $attachments : [$attachments];
52
53 $attachments = array_filter($attachments, function($file) {
54 $valid = file_exists($file) && is_readable($file);
55 if (!$valid) throw new NotificationException("Attachment $file is not valid!");
56 });
57
58 try {
59 return Wordpress::sendMail($recipient, $subject, $message, $headers, $attachments);
60 } catch (\Exception $e) {
61 throw new NotificationException($e->getMessage(), $e->getCode());
62 }
63 }
64 }