PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 1 year ago MailgunService.php 1 year ago PHPMailService.php 1 year ago SMTPService.php 1 year ago WpMailService.php 1 year ago
SMTPService.php
109 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 * @param $replyTo
45 */
46 public function __construct($from, $fromName, $host, $port, $secure, $username, $password, $replyTo)
47 {
48 parent::__construct($from, $fromName, $replyTo);
49 $this->host = $host;
50 $this->port = $port;
51 $this->secure = $secure;
52 $this->username = $username;
53 $this->password = $password;
54 }
55
56 /** @noinspection MoreThanThreeArgumentsInspection */
57 /**
58 * @param $to
59 * @param $subject
60 * @param $body
61 * @param array $bccEmails
62 * @param array $attachments
63 *
64 * @return mixed|void
65 * @throws Exception
66 * @SuppressWarnings(PHPMD)
67 */
68 public function send($to, $subject, $body, $bccEmails = [], $attachments = [])
69 {
70 $mail = new PHPMailer(true);
71
72 try {
73 //Server settings
74 $mail->isSMTP();
75 $mail->SMTPAuth = true;
76 $mail->SMTPSecure = $this->secure;
77 $mail->Host = $this->host;
78 $mail->Port = $this->port;
79 $mail->Username = $this->username;
80 $mail->Password = $this->password;
81
82 //Recipients
83 $mail->setFrom($this->from, $this->fromName);
84 $mail->addAddress($to);
85 $mail->addReplyTo(!empty($this->replyTo) ? $this->replyTo : $this->from);
86
87 foreach ($bccEmails as $bccEmail) {
88 $mail->addBCC($bccEmail);
89 }
90
91 foreach ($attachments as $attachment) {
92 if (!empty($attachment['content'])) {
93 $mail->addStringAttachment($attachment['content'], $attachment['name'], 'base64', $attachment['type']);
94 }
95 }
96
97 //Content
98 $mail->CharSet = 'UTF-8';
99 $mail->isHTML();
100 $mail->Subject = $subject;
101 $mail->Body = $body;
102
103 $mail->send();
104 } catch (Exception $e) {
105 throw $e;
106 }
107 }
108 }
109