PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.11
Booking for Appointments and Events Calendar – Amelia v1.2.11
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / Services / Notification / SMTPService.php
ameliabooking / src / Infrastructure / Services / Notification Last commit date
MailerFactory.php 5 years ago MailgunService.php 2 years ago PHPMailService.php 1 year ago SMTPService.php 1 year ago WpMailService.php 5 years ago
SMTPService.php
108 lines
1 <?php
2 /**
3 * @copyright © TMS-Plugins. All rights reserved.
4 * @licence See LICENCE.md for license details.
5 */
6
7 namespace AmeliaBooking\Infrastructure\Services\Notification;
8
9 use AmeliaBooking\Domain\Services\Notification\AbstractMailService;
10 use AmeliaBooking\Domain\Services\Notification\MailServiceInterface;
11 use Exception;
12 use AmeliaPHPMailer\PHPMailer\PHPMailer;
13
14 /**
15 * Class SMTPService
16 */
17 class SMTPService extends AbstractMailService implements MailServiceInterface
18 {
19 /** @var string */
20 private $host;
21
22 /** @var string */
23 private $port;
24
25 /** @var string */
26 private $username;
27
28 /** @var string */
29 private $password;
30
31 /** @var string */
32 private $secure;
33
34 /**
35 * SMTPService constructor.
36 *
37 * @param $from
38 * @param $fromName
39 * @param string $host
40 * @param string $port
41 * @param string $secure
42 * @param string $username
43 * @param string $password
44 */
45 public function __construct($from, $fromName, $host, $port, $secure, $username, $password)
46 {
47 parent::__construct($from, $fromName);
48 $this->host = $host;
49 $this->port = $port;
50 $this->secure = $secure;
51 $this->username = $username;
52 $this->password = $password;
53 }
54
55 /** @noinspection MoreThanThreeArgumentsInspection */
56 /**
57 * @param $to
58 * @param $subject
59 * @param $body
60 * @param array $bccEmails
61 * @param array $attachments
62 *
63 * @return mixed|void
64 * @throws Exception
65 * @SuppressWarnings(PHPMD)
66 */
67 public function send($to, $subject, $body, $bccEmails = [], $attachments = [])
68 {
69 $mail = new PHPMailer(true);
70
71 try {
72 //Server settings
73 $mail->isSMTP();
74 $mail->SMTPAuth = true;
75 $mail->SMTPSecure = $this->secure;
76 $mail->Host = $this->host;
77 $mail->Port = $this->port;
78 $mail->Username = $this->username;
79 $mail->Password = $this->password;
80
81 //Recipients
82 $mail->setFrom($this->from, $this->fromName);
83 $mail->addAddress($to);
84 $mail->addReplyTo($this->from);
85
86 foreach ($bccEmails as $bccEmail) {
87 $mail->addBCC($bccEmail);
88 }
89
90 foreach ($attachments as $attachment) {
91 if (!empty($attachment['content'])) {
92 $mail->addStringAttachment($attachment['content'], $attachment['name'], 'base64', $attachment['type']);
93 }
94 }
95
96 //Content
97 $mail->CharSet = 'UTF-8';
98 $mail->isHTML();
99 $mail->Subject = $subject;
100 $mail->Body = $body;
101
102 $mail->send();
103 } catch (Exception $e) {
104 throw $e;
105 }
106 }
107 }
108