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
PHPMailService.php
62 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 AmeliaPHPMailer\PHPMailer\Exception; |
| 12 | use AmeliaPHPMailer\PHPMailer\PHPMailer; |
| 13 | |
| 14 | /** |
| 15 | * Class PHPMailService |
| 16 | */ |
| 17 | class PHPMailService extends AbstractMailService implements MailServiceInterface |
| 18 | { |
| 19 | /** @noinspection MoreThanThreeArgumentsInspection */ |
| 20 | /** |
| 21 | * @param $to |
| 22 | * @param $subject |
| 23 | * @param $body |
| 24 | * @param array $bccEmails |
| 25 | * @param array $attachments |
| 26 | * |
| 27 | * @return mixed|void |
| 28 | * @throws Exception |
| 29 | * @SuppressWarnings(PHPMD) |
| 30 | */ |
| 31 | public function send($to, $subject, $body, $bccEmails = [], $attachments = []) |
| 32 | { |
| 33 | $mail = new PHPMailer(true); |
| 34 | |
| 35 | try { |
| 36 | //Recipients |
| 37 | $mail->setFrom($this->from, $this->fromName); |
| 38 | $mail->addAddress($to); |
| 39 | $mail->addReplyTo(!empty($this->replyTo) ? $this->replyTo : $this->from); |
| 40 | foreach ($bccEmails as $bccEmail) { |
| 41 | $mail->addBCC($bccEmail); |
| 42 | } |
| 43 | |
| 44 | foreach ($attachments as $attachment) { |
| 45 | if (!empty($attachment['content'])) { |
| 46 | $mail->addStringAttachment($attachment['content'], $attachment['name'], 'base64', $attachment['type']); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | //Content |
| 51 | $mail->CharSet = 'UTF-8'; |
| 52 | $mail->isHTML(); |
| 53 | $mail->Subject = $subject; |
| 54 | $mail->Body = $body; |
| 55 | |
| 56 | $mail->send(); |
| 57 | } catch (Exception $e) { |
| 58 | throw $e; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 |