diff --git a/index.php b/index.php index 9149447..d64eb7d 100644 --- a/index.php +++ b/index.php @@ -7,6 +7,7 @@ use \Frs\SessionManager; use \Frs\Output\HtmlOutput; use \Frs\Output\MailOutput; use \Frs\Output\Transport\StdoutTransport; +use \Frs\Output\Transport\MailTransport; $stdout = new StdoutTransport(); $ho = new HtmlOutput($stdout, dirname(__FILE__) . '/templates'); @@ -70,7 +71,8 @@ if (!$tpl_done && $sm->hasSessionToken()) { switch ($action) { case 'send': echo 'This would send the mail...'; - $mo = new MailOutput(dirname(__FILE__) . '/templates'); + $mt = new MailTransport(); + $mo = new MailOutput($mt, dirname(__FILE__) . '/templates'); $form_type = $_REQUEST['form_type']; $mo->setTemplate('mail_' . $form_type); $skey = 'form_' . $form_type; diff --git a/lib/Frs/Output/MailOutput.php b/lib/Frs/Output/MailOutput.php index b5fa3ae..a1a8a14 100644 --- a/lib/Frs/Output/MailOutput.php +++ b/lib/Frs/Output/MailOutput.php @@ -98,7 +98,10 @@ class MailOutput extends GenericOutput $this->setHeadersFromString($headers); $recipients = implode(', ', $this->recipients); // TODO: Check if any recipients in the first place - $mail_sent = mail($recipients, $this->subject, $mailbody, $this->getHeaders()); - return $mail_sent; + $this->transport->setRecipients($recipients); + $this->transport->setSubject($this->subject); + $this->transport->setHeaders($this->getHeaders()); + $this->transport->setContent($mailbody); + return $this->transport->send(); } } diff --git a/lib/Frs/Output/Transport/MailTransport.php b/lib/Frs/Output/Transport/MailTransport.php new file mode 100644 index 0000000..a177d98 --- /dev/null +++ b/lib/Frs/Output/Transport/MailTransport.php @@ -0,0 +1,36 @@ +content = $content; + } + + public function setRecipients($recipients) + { + $this->recipients = $recipients; + } + + public function setSubject($subject) + { + $this->subject = $subject; + } + + public function setHeaders($headers) + { + $this->headers = $headers; + } + + public function transmit() + { + return mail($this->recipients, $this->subject, $this->content, $this->headers); + } +} diff --git a/lib/Frs/Output/Transport/StdoutTransport.php b/lib/Frs/Output/Transport/StdoutTransport.php index 4549cc5..373ef50 100644 --- a/lib/Frs/Output/Transport/StdoutTransport.php +++ b/lib/Frs/Output/Transport/StdoutTransport.php @@ -14,5 +14,6 @@ class StdoutTransport implements TransportInterface public function transmit() { echo $this->content; + return true; } }