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
WpMailService.php
73 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 | |
| 13 | /** |
| 14 | * Class WpMailService |
| 15 | */ |
| 16 | class WpMailService extends AbstractMailService implements MailServiceInterface |
| 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 | $extension = pathinfo($attachment['name'], PATHINFO_EXTENSION); |
| 58 | $fileName = pathinfo($attachment['name'], PATHINFO_FILENAME); |
| 59 | $tmpFile = tempnam(sys_get_temp_dir(), $fileName . '_'); |
| 60 | if ( |
| 61 | $tmpFile && |
| 62 | file_put_contents($tmpFile, $attachment['content']) !== false && |
| 63 | @rename($tmpFile, $tmpFile .= '.' . $extension) !== false |
| 64 | ) { |
| 65 | $attachmentsLocations[] = $tmpFile; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | wp_mail($to, $subject, $body, $content, $attachmentsLocations); |
| 71 | } |
| 72 | } |
| 73 |