Bugfixes made on the interface

This commit is contained in:
Dave Mc Nicoll 2022-02-25 16:41:49 +00:00
parent bee7e25935
commit 34b850c780
2 changed files with 18 additions and 1 deletions

View File

@ -8,5 +8,7 @@ interface MailerInterface
public function setFrom($from) : self;
public function attach(\Swift_Attachment $attachment) : self;
public function setTo($to) : self;
}

View File

@ -15,6 +15,8 @@ class SwiftMailer implements MailerInterface
protected /*stringable|array*/ $cc;
protected /*stringable|array*/ $bcc;
protected array $attachments = [];
public function __construct(EmailConfiguration $configuration) {
$this->emailConfiguration = $configuration;
@ -32,9 +34,22 @@ class SwiftMailer implements MailerInterface
->setCC($this->cc ?? [])
->setBCC($this->bcc ?? [])
->setBody( $message, $html ? 'text/html' : 'text/plain' );
foreach ($this->attachments as $attachment) {
$swiftObj->attach($attachment);
}
$this->attachments = [];
return ( new \Swift_Mailer($this->transport) )->send($swiftObj);
}
public function attach(\Swift_Attachment $attachment) : self
{
$this->attachments[] = $attachment;
return $this;
}
public function setFrom(/*stringable|array*/ $from) : MailerInterface
{