- Work done on the Bug Email component

This commit is contained in:
Dave Mc Nicoll committed 2019-08-21 15:54:17 -04:00
1 parent ec873145d2
commit a7dcdf4ee7
8 files changed
+286 -139

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
<?php
namespace TheBugs\Email;
class EmailConfiguration
{
const AUTH_TYPE_SMTP = 1;
protected $type;
public $smtpHost = "";
public $smtpUsername = "";
public $smtpPassword = "";
public $smtpPort = 25;
public $smtpUseTLS = false;
public function __construct($type = self::AUTH_TYPE_SMTP)
{
$this->type = $type;
}
}
+12
View File
@@ -0,0 +1,12 @@
<?php
namespace TheBugs\Email;
interface MailerInterface
{
public function send(string $subject, string $message, bool $html = true) : bool;
public function setFrom($from) : self;
public function setTo($to) : self;
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace TheBugs\Email;
class SwiftMailer implements MailerInterface
{
protected $emailConfiguration;
protected $transport;
protected $from;
protected $to;
public function __construct(EmailConfiguration $configuration) {
$this->emailConfiguration = $configuration;
$this->transport = ( new \Swift_SmtpTransport($this->emailConfiguration->smtpHost, $this->emailConfiguration->smtpPort) )
->setUsername($this->emailConfiguration->smtpUsername)
->setPassword($this->emailConfiguration->smtpPassword);
}
public function send(string $subject, string $message, bool $html = true) : bool
{
$swiftObj = ( new \Swift_Message($subject) )
->setFrom( $this->from )
->setTo( $this->to )
->setBody( $message, $html ? 'text/html' : 'text/plain' );
return ( new \Swift_Mailer($this->transport) )->send($swiftObj);
}
public function setFrom($from) : MailerInterface
{
$this->from = $from;
return $this;
}
public function setTo($to) : MailerInterface
{
$this->to = $to;
return $this;
}
}