3 * log4php is a PHP port of the log4j java logging package.
5 * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
6 * <p>Design, strategies and part of the methods documentation are developed by log4j team
7 * (Ceki Gülcü as log4j project founder and
8 * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
10 * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
11 * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
13 * <p>This software is published under the terms of the LGPL License
14 * a copy of which has been included with this distribution in the LICENSE file.</p>
17 * @subpackage appenders
23 if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
27 require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
28 require_once(LOG4PHP_DIR . '/LoggerLog.php');
31 * Log events to an email address. It will be created an email for each event.
34 * {@link $smtpHost} (optional),
35 * {@link $port} (optional),
36 * {@link $from} (optional),
38 * {@link $subject} (optional).</p>
39 * <p>A layout is required.</p>
41 * @author Domenico Lordi <lordi@interfree.it>
42 * @author VxR <vxr@vxr.it>
43 * @version $Revision: 2 $
45 * @subpackage appenders
47 class LoggerAppenderMailEvent extends LoggerAppenderSkeleton {
50 * @var string 'from' field
55 * @var integer 'from' field
60 * @var string hostname.
65 * @var string 'subject' field
70 * @var string 'to' field
77 var $requiresLayout = true;
82 * @param string $name appender name
84 function LoggerAppenderMailEvent($name)
86 $this->LoggerAppenderSkeleton($name);
89 function activateOptions()
91 $this->closed = false;
102 function getFrom() { return $this->from; }
107 function getPort() { return $this->port; }
112 function getSmtpHost() { return $this->smtpHost; }
117 function getSubject() { return $this->subject; }
122 function getTo() { return $this->to; }
124 function setFrom($from) { $this->from = $from; }
125 function setPort($port) { $this->port = (int)$port; }
126 function setSmtpHost($smtphost) { $this->smtpHost = $smtpHost; }
127 function setSubject($subject) { $this->subject = $subject; }
128 function setTo($to) { $this->to = $to; }
130 function append($event)
132 $from = $this->getFrom();
133 $to = $this->getTo();
134 if (empty($from) or empty($to))
137 $smtpHost = $this->getSmtpHost();
138 $prevSmtpHost = ini_get('SMTP');
139 if (!empty($smtpHost)) {
140 ini_set('SMTP', $smtpHost);
142 $smtpHost = $prevSmtpHost;
145 $smtpPort = $this->getPort();
146 $prevSmtpPort= ini_get('smtp_port');
147 if ($smtpPort > 0 and $smtpPort < 65535) {
148 ini_set('smtp_port', $smtpPort);
150 $smtpPort = $prevSmtpPort;
154 "LoggerAppenderMailEvent::append()" .
155 ":from=[{$from}]:to=[{$to}]:smtpHost=[{$smtpHost}]:smtpPort=[{$smtpPort}]"
158 if (!@mail( $to, $this->getSubject(),
159 $this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event),
162 LoggerLog::debug("LoggerAppenderMailEvent::append() mail error");
165 ini_set('SMTP', $prevSmtpHost);
166 ini_set('smtp_port', $prevSmtpPort);