diff --git a/library/log4php/appenders/LoggerAppenderMail.php b/library/log4php/appenders/LoggerAppenderMail.php new file mode 100644 --- /dev/null +++ b/library/log4php/appenders/LoggerAppenderMail.php @@ -0,0 +1,136 @@ +layout !== null) { + $this->body .= $this->layout->format($event); + } + } + + public function close() { + if ($this->closed != true) { + $from = $this->from; + $to = $this->to; + + if (!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) { + $subject = $this->subject; + if (!$this->dry) { + mail( + $to, $subject, + $this->layout->getHeader() . $this->body . $this->layout->getFooter(), + "From: {$from}\r\n"); + } else { + echo "DRY MODE OF MAIL APP.: Send mail to: " . $to . " with content: " . $this->body; + } + } + $this->closed = true; + } + } + + /** Sets the 'subject' parameter. */ + public function setSubject($subject) { + $this->setString('subject', $subject); + } + + /** Returns the 'subject' parameter. */ + public function getSubject() { + return $this->subject; + } + + /** Sets the 'to' parameter. */ + public function setTo($to) { + $this->setString('to', $to); + } + + /** Returns the 'to' parameter. */ + public function getTo() { + return $this->to; + } + + /** Sets the 'from' parameter. */ + public function setFrom($from) { + $this->setString('from', $from); + } + + /** Returns the 'from' parameter. */ + public function getFrom() { + return $this->from; + } + + /** Enables or disables dry mode. */ + public function setDry($dry) { + $this->setBoolean('dry', $dry); + } +}