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
WpMailService.php
64 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) |
| 25 | { |
| 26 | parent::__construct($from, $fromName); |
| 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 = ['Content-Type: text/html; charset=UTF-8','From: ' . $this->fromName . ' <' . $this->from . '>']; |
| 44 | |
| 45 | if ($bccEmails) { |
| 46 | $content[] = 'Bcc:' . implode(', ', $bccEmails); |
| 47 | } |
| 48 | |
| 49 | $attachmentsLocations = []; |
| 50 | |
| 51 | foreach ($attachments as $attachment) { |
| 52 | if (!empty($attachment['content']) && |
| 53 | ($tmpFile = tempnam(sys_get_temp_dir(), 'cal_')) !== false && |
| 54 | file_put_contents($tmpFile, $attachment['content']) !== false && |
| 55 | @rename($tmpFile, $tmpFile .= '.ics') !== false |
| 56 | ) { |
| 57 | $attachmentsLocations[] = $tmpFile; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | wp_mail($to, $subject, $body, $content, $attachmentsLocations); |
| 62 | } |
| 63 | } |
| 64 |