summaryrefslogtreecommitdiff
path: root/src/Mail/Mailer.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-26 21:28:49 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-26 21:31:18 +0200
commit6187eed3bb08f200050a3078bd762b5731dfbe78 (patch)
tree06e0b08294c66449ed5f9f046a3bfe2097c7b4ad /src/Mail/Mailer.php
parentbc5764b33ffc8a92dfa1d788ba2a204dd991c3d9 (diff)
parentd36de2d26f5af76d5d4f34f8620694c6d0368983 (diff)
Merge remote-tracking branch 'MyIgel/mailing'
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;
+ }
+}