summaryrefslogtreecommitdiff
path: root/src/Mail/Mailer.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-05 13:40:03 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-05 13:44:43 +0200
commit01e9c22695a3e495f07ab445750221af72e09fe4 (patch)
tree63c01a396d289f5f1e4d11259654e772300ff98c /src/Mail/Mailer.php
parent9d34f371cb9c5ab0d60bd3158678b9cc9da6cc80 (diff)
Implemented mailing abstraction
Closes #434
Diffstat (limited to 'src/Mail/Mailer.php')
-rw-r--r--src/Mail/Mailer.php79
1 files changed, 79 insertions, 0 deletions
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 @@
+<?php
+
+namespace Engelsystem\Mail;
+
+use Engelsystem\Renderer\Renderer;
+use Swift_Mailer as SwiftMailer;
+use Swift_Message as SwiftMessage;
+
+class Mailer
+{
+ /** @var SwiftMailer */
+ protected $mailer;
+
+ /** @var Renderer|null */
+ protected $view;
+
+ /** @var string */
+ protected $fromAddress = '';
+
+ /** @var string */
+ protected $fromName = null;
+
+ public function __construct(SwiftMailer $mailer)
+ {
+ $this->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;
+ }
+}