[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/log4php/appenders/ -> LoggerAppenderMailEvent.php (source)

   1  <?php
   2  /**
   3   * log4php is a PHP port of the log4j java logging package.
   4   * 
   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>
   9   *
  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>
  12   *
  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>
  15   * 
  16   * @package log4php
  17   * @subpackage appenders
  18   */
  19  
  20  /**
  21   * @ignore 
  22   */
  23  if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  24  
  25  /**
  26   */
  27  require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  28  require_once (LOG4PHP_DIR . '/LoggerLog.php');
  29  
  30  /**
  31   * Log events to an email address. It will be created an email for each event. 
  32   *
  33   * <p>Parameters are 
  34   * {@link $smtpHost} (optional), 
  35   * {@link $port} (optional), 
  36   * {@link $from} (optional), 
  37   * {@link $to}, 
  38   * {@link $subject} (optional).</p>
  39   * <p>A layout is required.</p>
  40   *
  41   * @author Domenico Lordi <lordi@interfree.it>
  42   * @author VxR <vxr@vxr.it>
  43   * @version $Revision: 1.10 $
  44   * @package log4php
  45   * @subpackage appenders
  46   */
  47  class LoggerAppenderMailEvent extends LoggerAppenderSkeleton {
  48  
  49      /**
  50       * @var string 'from' field
  51       */
  52      var $from           = null;
  53  
  54      /**
  55       * @var integer 'from' field
  56       */
  57      var $port           = 25;
  58  
  59      /**
  60       * @var string hostname. 
  61       */
  62      var $smtpHost       = null;
  63  
  64      /**
  65       * @var string 'subject' field
  66       */
  67      var $subject        = '';
  68  
  69      /**
  70       * @var string 'to' field
  71       */
  72      var $to             = null;
  73      
  74      /**
  75       * @access private
  76       */
  77      var $requiresLayout = true;
  78  
  79      /**
  80       * Constructor.
  81       *
  82       * @param string $name appender name
  83       */
  84      function LoggerAppenderMailEvent($name)
  85      {
  86          $this->LoggerAppenderSkeleton($name);
  87      }
  88  
  89      function activateOptions()
  90      { 
  91          $this->closed = false;
  92      }
  93      
  94      function close()
  95      {
  96          $this->closed = true;
  97      }
  98  
  99      /**
 100       * @return string
 101       */
 102      function getFrom()      { return $this->from; }
 103      
 104      /**
 105       * @return integer
 106       */
 107      function getPort()      { return $this->port; }
 108      
 109      /**
 110       * @return string
 111       */
 112      function getSmtpHost()  { return $this->smtpHost; }
 113      
 114      /**
 115       * @return string
 116       */
 117      function getSubject()   { return $this->subject; }
 118  
 119      /**
 120       * @return string
 121       */
 122      function getTo()        { return $this->to; }
 123  
 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; }
 129  
 130      function append($event)
 131      {
 132          $from = $this->getFrom();
 133          $to   = $this->getTo();
 134          if (empty($from) or empty($to))
 135              return;
 136      
 137          $smtpHost = $this->getSmtpHost();
 138          $prevSmtpHost = ini_get('SMTP');
 139          if (!empty($smtpHost)) {
 140              ini_set('SMTP', $smtpHost);
 141          } else {
 142              $smtpHost = $prevSmtpHost;
 143          } 
 144  
 145          $smtpPort = $this->getPort();
 146          $prevSmtpPort= ini_get('smtp_port');        
 147          if ($smtpPort > 0 and $smtpPort < 65535) {
 148              ini_set('smtp_port', $smtpPort);
 149          } else {
 150              $smtpPort = $prevSmtpPort;
 151          } 
 152          
 153          LoggerLog::debug(
 154              "LoggerAppenderMailEvent::append()" . 
 155              ":from=[{$from}]:to=[{$to}]:smtpHost=[{$smtpHost}]:smtpPort=[{$smtpPort}]"
 156          ); 
 157          
 158          if (!@mail( $to, $this->getSubject(), 
 159              $this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event), 
 160              "From: {$from}\r\n"
 161          )) {
 162              LoggerLog::debug("LoggerAppenderMailEvent::append() mail error");
 163          }
 164              
 165          ini_set('SMTP',         $prevSmtpHost);
 166          ini_set('smtp_port',    $prevSmtpPort);
 167      }
 168  }
 169  
 170  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7