From 01e9c22695a3e495f07ab445750221af72e09fe4 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 5 Sep 2018 13:40:03 +0200 Subject: Implemented mailing abstraction Closes #434 --- src/Mail/Mailer.php | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/Mail/Mailer.php (limited to 'src/Mail/Mailer.php') diff --git a/src/Mail/Mailer.php b/src/Mail/Mailer.php new file mode 100644 index 00000000..ed800986 --- /dev/null +++ b/src/Mail/Mailer.php @@ -0,0 +1,79 @@ +mailer = $mailer; + } + + /** + * Send the mail + * + * @param string|string[] $to + * @param string $subject + * @param string $body + * @return int + */ + public function send($to, string $subject, string $body): int + { + /** @var SwiftMessage $message */ + $message = $this->mailer->createMessage(); + $message->setTo((array)$to) + ->setFrom($this->fromAddress, $this->fromName) + ->setSubject($subject) + ->setBody($body); + + return $this->mailer->send($message); + } + + /** + * @return string + */ + public function getFromAddress(): string + { + return $this->fromAddress; + } + + /** + * @param string $fromAddress + */ + public function setFromAddress(string $fromAddress) + { + $this->fromAddress = $fromAddress; + } + + /** + * @return string + */ + public function getFromName(): string + { + return $this->fromName; + } + + /** + * @param string $fromName + */ + public function setFromName(string $fromName) + { + $this->fromName = $fromName; + } +} -- cgit v1.2.3-54-g00ecf