. */ namespace SP\Providers\Mail; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\PHPMailer; use SP\Domain\Providers\MailerInterface; /** * A wrapper for PHPMailer */ final class PhpMailerWrapper implements MailerInterface { private PHPMailer $mailer; public function __construct(PHPMailer $mailer) { $this->mailer = $mailer; } public function isHtml(): MailerInterface { $this->mailer->isHTML(); return $this; } /** * @throws \SP\Providers\Mail\MailProviderException */ public function addAddress(string $address): MailerInterface { try { $this->mailer->addAddress($address); } catch (Exception $e) { throw new MailProviderException($e); } return $this; } public function subject(string $subject): MailerInterface { $this->mailer->set('Subject', $subject); return $this; } public function body(string $body): MailerInterface { $this->mailer->set('Body', $body); return $this; } /** * @throws \SP\Providers\Mail\MailProviderException */ public function send(): bool { try { return $this->mailer->send(); } catch (Exception $e) { throw new MailProviderException($e); } } public function getMailer(): PHPMailer { return $this->mailer; } public function getToAddresses(): array { return $this->mailer->getToAddresses(); } }