diff --git a/src/Email/MailerInterface.php b/src/Email/MailerInterface.php index eddf706..fac8716 100644 --- a/src/Email/MailerInterface.php +++ b/src/Email/MailerInterface.php @@ -8,5 +8,7 @@ interface MailerInterface public function setFrom($from) : self; + public function attach(\Swift_Attachment $attachment) : self; + public function setTo($to) : self; } \ No newline at end of file diff --git a/src/Email/SwiftMailer.php b/src/Email/SwiftMailer.php index cca9b3c..e18bf98 100644 --- a/src/Email/SwiftMailer.php +++ b/src/Email/SwiftMailer.php @@ -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 {