PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 4 months ago MailgunService.php 3 months ago OutlookMiddlewareService.php 4 months ago OutlookService.php 6 months ago PHPMailService.php 6 months ago SMTPService.php 6 months ago WpMailService.php 6 months ago
SMTPService.php
110 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Infrastructure\Services\Notification;
9
10 use AmeliaBooking\Domain\Services\Notification\AbstractMailService;
11 use AmeliaBooking\Domain\Services\Notification\MailServiceInterface;
12 use Exception;
13 use AmeliaVendor\PHPMailer\PHPMailer\PHPMailer;
14
15 /**
16 * Class SMTPService
17 */
18 class SMTPService extends AbstractMailService implements MailServiceInterface
19 {
20 /** @var string */
21 private $host;
22
23 /** @var int */
24 private $port;
25
26 /** @var string */
27 private $username;
28
29 /** @var string */
30 private $password;
31
32 /** @var string */
33 private $secure;
34
35 /**
36 * SMTPService constructor.
37 *
38 * @param $from
39 * @param $fromName
40 * @param string $host
41 * @param int $port
42 * @param string $secure
43 * @param string $username
44 * @param string $password
45 * @param $replyTo
46 */
47 public function __construct($from, $fromName, $host, $port, $secure, $username, $password, $replyTo)
48 {
49 parent::__construct($from, $fromName, $replyTo);
50 $this->host = $host;
51 $this->port = $port;
52 $this->secure = $secure;
53 $this->username = $username;
54 $this->password = $password;
55 }
56
57 /** @noinspection MoreThanThreeArgumentsInspection */
58 /**
59 * @param $to
60 * @param $subject
61 * @param $body
62 * @param array $bccEmails
63 * @param array $attachments
64 *
65 * @return mixed|void
66 * @throws Exception
67 * @SuppressWarnings(PHPMD)
68 */
69 public function send($to, $subject, $body, $bccEmails = [], $attachments = [])
70 {
71 $mail = new PHPMailer(true);
72
73 try {
74 //Server settings
75 $mail->isSMTP();
76 $mail->SMTPAuth = true;
77 $mail->SMTPSecure = $this->secure;
78 $mail->Host = $this->host;
79 $mail->Port = $this->port;
80 $mail->Username = $this->username;
81 $mail->Password = $this->password;
82
83 //Recipients
84 $mail->setFrom($this->from, $this->fromName);
85 $mail->addAddress($to);
86 $mail->addReplyTo(!empty($this->replyTo) ? $this->replyTo : $this->from);
87
88 foreach ($bccEmails as $bccEmail) {
89 $mail->addBCC($bccEmail);
90 }
91
92 foreach ($attachments as $attachment) {
93 if (!empty($attachment['content'])) {
94 $mail->addStringAttachment($attachment['content'], $attachment['name'], 'base64', $attachment['type']);
95 }
96 }
97
98 //Content
99 $mail->CharSet = 'UTF-8';
100 $mail->isHTML();
101 $mail->Subject = $subject;
102 $mail->Body = $body;
103
104 $mail->send();
105 } catch (Exception $e) {
106 throw $e;
107 }
108 }
109 }
110