PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 / WpMailService.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
WpMailService.php
73 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
12 /**
13 * Class WpMailService
14 */
15 class WpMailService extends AbstractMailService implements MailServiceInterface
16 {
17
18 /**
19 * WpMailService constructor.
20 *
21 * @param $from
22 * @param $fromName
23 */
24 public function __construct($from, $fromName, $replyTo)
25 {
26 parent::__construct($from, $fromName, $replyTo);
27 }
28
29 /** @noinspection MoreThanThreeArgumentsInspection */
30 /**
31 * @param $to
32 * @param $subject
33 * @param $body
34 * @param array $bccEmails
35 * @param array $attachments
36 *
37 * @return mixed|void
38 * @SuppressWarnings(PHPMD)
39 */
40
41 public function send($to, $subject, $body, $bccEmails = [], $attachments = [])
42 {
43 $content = [
44 'Content-Type: text/html; charset=UTF-8',
45 'From: ' . $this->fromName . ' <' . $this->from . '>',
46 'Reply-To: ' . (!empty($this->replyTo) ? $this->replyTo : $this->from)
47 ];
48
49 if ($bccEmails) {
50 $content[] = 'Bcc:' . implode(', ', $bccEmails);
51 }
52
53 $attachmentsLocations = [];
54
55 foreach ($attachments as $attachment) {
56 if (!empty($attachment['content'])) {
57 $isInvoice = strpos($attachment['type'], 'pdf') !== false;
58 if ($isInvoice) {
59 $tmpFile = tempnam(sys_get_temp_dir(), 'Invoice_');
60 } else {
61 $tmpFile = tempnam(sys_get_temp_dir(), 'cal_');
62 }
63 if ($tmpFile &&
64 file_put_contents($tmpFile, $attachment['content']) !== false &&
65 @rename($tmpFile, $tmpFile .= ($isInvoice ? '.pdf' : '.ics')) !== false) {
66 $attachmentsLocations[] = $tmpFile;
67 }
68 }
69 }
70
71 wp_mail($to, $subject, $body, $content, $attachmentsLocations);
72 }
73 }