Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-smtp.php

    r17676 r13425  
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.1                                                            |
     5|   Version: 2.0.4                                                          |
    66|   Contact: via sourceforge.net support pages (also www.codeworxtech.com)  |
    77|      Info: http://phpmailer.sourceforge.net                               |
    88|   Support: http://sourceforge.net/projects/phpmailer/                     |
    99| ------------------------------------------------------------------------- |
    10 |     Admin: Andy Prevost (project admininistrator)                         |
    11 |   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
    12 |          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         |
    13 |   Founder: Brent R. Matzelle (original founder)                           |
    14 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved.               |
     10|    Author: Andy Prevost (project admininistrator)                         |
     11|    Author: Brent R. Matzelle (original founder)                           |
     12| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved.               |
    1513| Copyright (c) 2001-2003, Brent R. Matzelle                                |
    1614| ------------------------------------------------------------------------- |
     
    2624| - Oursourcing (highly qualified programmers and graphic designers)        |
    2725'---------------------------------------------------------------------------'
    28 */
    29 
    30 /**
    31  * PHPMailer - PHP SMTP email transport class
    32  * NOTE: Designed for use with PHP version 5 and up
    33  * @package PHPMailer
    34  * @author Andy Prevost
    35  * @author Marcus Bointon
    36  * @copyright 2004 - 2008 Andy Prevost
    37  * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
    38  * @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $
    3926 */
    40 
    4127/**
    4228 * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
     
    4430 * error. SMTP also provides some utility methods for sending mail
    4531 * to an SMTP server.
    46  * original author: Chris Ryan
     32 * @package PHPMailer
     33 * @author Chris Ryan
    4734 */
    4835
    49 class SMTP {
     36class SMTP
     37{
    5038  /**
    5139   *  SMTP server port
    5240   *  @var int
    5341   */
    54   public $SMTP_PORT = 25;
     42  var $SMTP_PORT = 25;
    5543
    5644  /**
     
    5846   *  @var string
    5947   */
    60   public $CRLF = "\r\n";
     48  var $CRLF = "\r\n";
    6149
    6250  /**
     
    6452   *  @var bool
    6553   */
    66   public $do_debug;       // the level of debug to perform
     54  var $do_debug;       # the level of debug to perform
    6755
    6856  /**
     
    7058   *  @var bool
    7159   */
    72   public $do_verp = false;
    73 
    74   /////////////////////////////////////////////////
    75   // PROPERTIES, PRIVATE AND PROTECTED
    76   /////////////////////////////////////////////////
    77 
    78   private $smtp_conn; // the socket to the server
    79   private $error;     // error if any on the last call
    80   private $helo_rply; // the reply the server sent to us for HELO
     60  var $do_verp = false;
     61
     62  /**#@+
     63   * @access private
     64   */
     65  var $smtp_conn;      # the socket to the server
     66  var $error;          # error if any on the last call
     67  var $helo_rply;      # the reply the server sent to us for HELO
     68  /**#@-*/
    8169
    8270  /**
     
    8573   * @return void
    8674   */
    87   public function __construct() {
     75  function SMTP() {
    8876    $this->smtp_conn = 0;
    8977    $this->error = null;
     
    9381  }
    9482
    95   /////////////////////////////////////////////////
    96   // CONNECTION FUNCTIONS
    97   /////////////////////////////////////////////////
     83  /*************************************************************
     84   *                    CONNECTION FUNCTIONS                  *
     85   ***********************************************************/
    9886
    9987  /**
     
    11098   * @return bool
    11199   */
    112   public function Connect($host, $port = 0, $tval = 30) {
    113     // set the error val to null so there is no confusion
     100  function Connect($host,$port=0,$tval=30) {
     101    # set the error val to null so there is no confusion
    114102    $this->error = null;
    115103
    116     // make sure we are __not__ connected
     104    # make sure we are __not__ connected
    117105    if($this->connected()) {
    118       // already connected, generate error
     106      # ok we are connected! what should we do?
     107      # for now we will just give an error saying we
     108      # are already connected
    119109      $this->error = array("error" => "Already connected to a server");
    120110      return false;
     
    125115    }
    126116
    127     // connect to the smtp server
    128     $this->smtp_conn = @fsockopen($host,    // the host of the server
    129                                  $port,    // the port to use
    130                                  $errno,   // error number if any
    131                                  $errstr,  // error message if any
    132                                  $tval);   // give up after ? secs
    133     // verify we connected properly
     117    #connect to the smtp server
     118    $this->smtp_conn = fsockopen($host,    # the host of the server
     119                                 $port,    # the port to use
     120                                 $errno,   # error number if any
     121                                 $errstr,  # error message if any
     122                                 $tval);   # give up after ? secs
     123    # verify we connected properly
    134124    if(empty($this->smtp_conn)) {
    135125      $this->error = array("error" => "Failed to connect to server",
     
    137127                           "errstr" => $errstr);
    138128      if($this->do_debug >= 1) {
    139         echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
    140       }
    141       return false;
    142     }
    143 
    144     // SMTP server can take longer to respond, give longer timeout for first read
    145     // Windows does not have support for this timeout function
     129        echo "SMTP -> ERROR: " . $this->error["error"] .
     130                 ": $errstr ($errno)" . $this->CRLF;
     131      }
     132      return false;
     133    }
     134
     135    # sometimes the SMTP server takes a little longer to respond
     136    # so we will give it a longer timeout for the first read
     137    // Windows still does not have support for this timeout function
    146138    if(substr(PHP_OS, 0, 3) != "WIN")
    147139     socket_set_timeout($this->smtp_conn, $tval, 0);
    148140
    149     // get any announcement
     141    # get any announcement stuff
    150142    $announce = $this->get_lines();
    151143
    152     if($this->do_debug >= 2) {
    153       echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
    154     }
    155 
    156     return true;
    157   }
    158 
    159   /**
    160    * Initiate a TLS communication with the server.
    161    *
    162    * SMTP CODE 220 Ready to start TLS
    163    * SMTP CODE 501 Syntax error (no parameters allowed)
    164    * SMTP CODE 454 TLS not available due to temporary reason
    165    * @access public
    166    * @return bool success
    167    */
    168   public function StartTLS() {
    169     $this->error = null; # to avoid confusion
    170 
    171     if(!$this->connected()) {
    172       $this->error = array("error" => "Called StartTLS() without being connected");
    173       return false;
    174     }
    175 
    176     fputs($this->smtp_conn,"STARTTLS" . $this->CRLF);
    177 
    178     $rply = $this->get_lines();
    179     $code = substr($rply,0,3);
    180 
    181     if($this->do_debug >= 2) {
    182       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
    183     }
    184 
    185     if($code != 220) {
    186       $this->error =
    187          array("error"     => "STARTTLS not accepted from server",
    188                "smtp_code" => $code,
    189                "smtp_msg"  => substr($rply,4));
    190       if($this->do_debug >= 1) {
    191         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    192       }
    193       return false;
    194     }
    195 
    196     // Begin encrypted connection
    197     if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
    198       return false;
     144    # set the timeout  of any socket functions at 1/10 of a second
     145    //if(function_exists("socket_set_timeout"))
     146    //   socket_set_timeout($this->smtp_conn, 0, 100000);
     147
     148    if($this->do_debug >= 2) {
     149      echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
    199150    }
    200151
     
    208159   * @return bool
    209160   */
    210   public function Authenticate($username, $password) {
     161  function Authenticate($username, $password) {
    211162    // Start authentication
    212163    fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
     
    221172              "smtp_msg" => substr($rply,4));
    222173      if($this->do_debug >= 1) {
    223         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     174        echo "SMTP -> ERROR: " . $this->error["error"] .
     175                 ": " . $rply . $this->CRLF;
    224176      }
    225177      return false;
     
    238190              "smtp_msg" => substr($rply,4));
    239191      if($this->do_debug >= 1) {
    240         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     192        echo "SMTP -> ERROR: " . $this->error["error"] .
     193                 ": " . $rply . $this->CRLF;
    241194      }
    242195      return false;
     
    255208              "smtp_msg" => substr($rply,4));
    256209      if($this->do_debug >= 1) {
    257         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     210        echo "SMTP -> ERROR: " . $this->error["error"] .
     211                 ": " . $rply . $this->CRLF;
    258212      }
    259213      return false;
     
    265219  /**
    266220   * Returns true if connected to a server otherwise false
    267    * @access public
    268    * @return bool
    269    */
    270   public function Connected() {
     221   * @access private
     222   * @return bool
     223   */
     224  function Connected() {
    271225    if(!empty($this->smtp_conn)) {
    272226      $sock_status = socket_get_status($this->smtp_conn);
    273227      if($sock_status["eof"]) {
    274         // the socket is valid but we are not connected
     228        # hmm this is an odd situation... the socket is
     229        # valid but we are not connected anymore
    275230        if($this->do_debug >= 1) {
    276             echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
     231            echo "SMTP -> NOTICE:" . $this->CRLF .
     232                 "EOF caught while checking if connected";
    277233        }
    278234        $this->Close();
    279235        return false;
    280236      }
    281       return true; // everything looks good
     237      return true; # everything looks good
    282238    }
    283239    return false;
     
    291247   * @return void
    292248   */
    293   public function Close() {
    294     $this->error = null; // so there is no confusion
     249  function Close() {
     250    $this->error = null; # so there is no confusion
    295251    $this->helo_rply = null;
    296252    if(!empty($this->smtp_conn)) {
    297       // close the connection and cleanup
     253      # close the connection and cleanup
    298254      fclose($this->smtp_conn);
    299255      $this->smtp_conn = 0;
     
    301257  }
    302258
    303   /////////////////////////////////////////////////
    304   // SMTP COMMANDS
    305   /////////////////////////////////////////////////
     259  /***************************************************************
     260   *                        SMTP COMMANDS                       *
     261   *************************************************************/
    306262
    307263  /**
     
    310266   * that is to be send with the headers. Each header needs to be
    311267   * on a single line followed by a <CRLF> with the message headers
    312    * and the message body being seperated by and additional <CRLF>.
     268   * and the message body being separated by and additional <CRLF>.
    313269   *
    314270   * Implements rfc 821: DATA <CRLF>
     
    324280   * @return bool
    325281   */
    326   public function Data($msg_data) {
    327     $this->error = null; // so no confusion is caused
     282  function Data($msg_data) {
     283    $this->error = null; # so no confusion is caused
    328284
    329285    if(!$this->connected()) {
     
    339295
    340296    if($this->do_debug >= 2) {
    341       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     297      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    342298    }
    343299
     
    348304              "smtp_msg" => substr($rply,4));
    349305      if($this->do_debug >= 1) {
    350         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    351       }
    352       return false;
    353     }
    354 
    355     /* the server is ready to accept data!
    356      * according to rfc 821 we should not send more than 1000
    357      * including the CRLF
    358      * characters on a single line so we will break the data up
    359      * into lines by \r and/or \n then if needed we will break
    360      * each of those into smaller lines to fit within the limit.
    361      * in addition we will be looking for lines that start with
    362      * a period '.' and append and additional period '.' to that
    363      * line. NOTE: this does not count towards limit.
    364      */
    365 
    366     // normalize the line breaks so we know the explode works
     306        echo "SMTP -> ERROR: " . $this->error["error"] .
     307                 ": " . $rply . $this->CRLF;
     308      }
     309      return false;
     310    }
     311
     312    # the server is ready to accept data!
     313    # according to rfc 821 we should not send more than 1000
     314    # including the CRLF
     315    # characters on a single line so we will break the data up
     316    # into lines by \r and/or \n then if needed we will break
     317    # each of those into smaller lines to fit within the limit.
     318    # in addition we will be looking for lines that start with
     319    # a period '.' and append and additional period '.' to that
     320    # line. NOTE: this does not count towards are limit.
     321
     322    # normalize the line breaks so we know the explode works
    367323    $msg_data = str_replace("\r\n","\n",$msg_data);
    368324    $msg_data = str_replace("\r","\n",$msg_data);
    369325    $lines = explode("\n",$msg_data);
    370326
    371     /* we need to find a good way to determine is headers are
    372      * in the msg_data or if it is a straight msg body
    373      * currently I am assuming rfc 822 definitions of msg headers
    374      * and if the first field of the first line (':' sperated)
    375      * does not contain a space then it _should_ be a header
    376      * and we can process all lines before a blank "" line as
    377      * headers.
    378      */
    379 
     327    # we need to find a good way to determine is headers are
     328    # in the msg_data or if it is a straight msg body
     329    # currently I am assuming rfc 822 definitions of msg headers
     330    # and if the first field of the first line (':' sperated)
     331    # does not contain a space then it _should_ be a header
     332    # and we can process all lines before a blank "" line as
     333    # headers.
    380334    $field = substr($lines[0],0,strpos($lines[0],":"));
    381335    $in_headers = false;
     
    384338    }
    385339
    386     $max_line_length = 998; // used below; set here for ease in change
     340    $max_line_length = 998; # used below; set here for ease in change
    387341
    388342    while(list(,$line) = @each($lines)) {
     
    391345        $in_headers = false;
    392346      }
    393       // ok we need to break this line up into several smaller lines
     347      # ok we need to break this line up into several
     348      # smaller lines
    394349      while(strlen($line) > $max_line_length) {
    395350        $pos = strrpos(substr($line,0,$max_line_length)," ");
    396351
    397         // Patch to fix DOS attack
     352        # Patch to fix DOS attack
    398353        if(!$pos) {
    399354          $pos = $max_line_length - 1;
    400           $lines_out[] = substr($line,0,$pos);
    401           $line = substr($line,$pos);
    402         } else {
    403           $lines_out[] = substr($line,0,$pos);
    404           $line = substr($line,$pos + 1);
    405355        }
    406356
    407         /* if processing headers add a LWSP-char to the front of new line
    408          * rfc 822 on long msg headers
    409          */
     357        $lines_out[] = substr($line,0,$pos);
     358        $line = substr($line,$pos + 1);
     359        # if we are processing headers we need to
     360        # add a LWSP-char to the front of the new line
     361        # rfc 822 on long msg headers
    410362        if($in_headers) {
    411363          $line = "\t" . $line;
     
    414366      $lines_out[] = $line;
    415367
    416       // send the lines to the server
     368      # now send the lines to the server
    417369      while(list(,$line_out) = @each($lines_out)) {
    418370        if(strlen($line_out) > 0)
     
    426378    }
    427379
    428     // message data has been sent
     380    # ok all the message data has been sent so lets get this
     381    # over with aleady
    429382    fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
    430383
     
    433386
    434387    if($this->do_debug >= 2) {
    435       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     388      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    436389    }
    437390
     
    442395              "smtp_msg" => substr($rply,4));
    443396      if($this->do_debug >= 1) {
    444         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    445       }
    446       return false;
    447     }
    448     return true;
     397        echo "SMTP -> ERROR: " . $this->error["error"] .
     398                 ": " . $rply . $this->CRLF;
     399      }
     400      return false;
     401    }
     402    return true;
     403  }
     404
     405  /**
     406   * Expand takes the name and asks the server to list all the
     407   * people who are members of the _list_. Expand will return
     408   * back and array of the result or false if an error occurs.
     409   * Each value in the array returned has the format of:
     410   *     [ <full-name> <sp> ] <path>
     411   * The definition of <path> is defined in rfc 821
     412   *
     413   * Implements rfc 821: EXPN <SP> <string> <CRLF>
     414   *
     415   * SMTP CODE SUCCESS: 250
     416   * SMTP CODE FAILURE: 550
     417   * SMTP CODE ERROR  : 500,501,502,504,421
     418   * @access public
     419   * @return string array
     420   */
     421  function Expand($name) {
     422    $this->error = null; # so no confusion is caused
     423
     424    if(!$this->connected()) {
     425      $this->error = array(
     426            "error" => "Called Expand() without being connected");
     427      return false;
     428    }
     429
     430    fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
     431
     432    $rply = $this->get_lines();
     433    $code = substr($rply,0,3);
     434
     435    if($this->do_debug >= 2) {
     436      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     437    }
     438
     439    if($code != 250) {
     440      $this->error =
     441        array("error" => "EXPN not accepted from server",
     442              "smtp_code" => $code,
     443              "smtp_msg" => substr($rply,4));
     444      if($this->do_debug >= 1) {
     445        echo "SMTP -> ERROR: " . $this->error["error"] .
     446                 ": " . $rply . $this->CRLF;
     447      }
     448      return false;
     449    }
     450
     451    # parse the reply and place in our array to return to user
     452    $entries = explode($this->CRLF,$rply);
     453    while(list(,$l) = @each($entries)) {
     454      $list[] = substr($l,4);
     455    }
     456
     457    return $list;
    449458  }
    450459
     
    461470   * @return bool
    462471   */
    463   public function Hello($host = '') {
    464     $this->error = null; // so no confusion is caused
     472  function Hello($host="") {
     473    $this->error = null; # so no confusion is caused
    465474
    466475    if(!$this->connected()) {
     
    470479    }
    471480
    472     // if hostname for HELO was not specified send default
     481    # if a hostname for the HELO was not specified determine
     482    # a suitable one to send
    473483    if(empty($host)) {
    474       // determine appropriate default to send to server
     484      # we need to determine some sort of appopiate default
     485      # to send to the server
    475486      $host = "localhost";
    476487    }
    477488
    478489    // Send extended hello first (RFC 2821)
    479     if(!$this->SendHello("EHLO", $host)) {
    480       if(!$this->SendHello("HELO", $host)) {
    481         return false;
    482       }
     490    if(!$this->SendHello("EHLO", $host))
     491    {
     492      if(!$this->SendHello("HELO", $host))
     493          return false;
    483494    }
    484495
     
    491502   * @return bool
    492503   */
    493   private function SendHello($hello, $host) {
     504  function SendHello($hello, $host) {
    494505    fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
    495506
     
    498509
    499510    if($this->do_debug >= 2) {
    500       echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
     511      echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
    501512    }
    502513
     
    507518              "smtp_msg" => substr($rply,4));
    508519      if($this->do_debug >= 1) {
    509         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     520        echo "SMTP -> ERROR: " . $this->error["error"] .
     521                 ": " . $rply . $this->CRLF;
    510522      }
    511523      return false;
     
    515527
    516528    return true;
     529  }
     530
     531  /**
     532   * Gets help information on the keyword specified. If the keyword
     533   * is not specified then returns generic help, ussually contianing
     534   * A list of keywords that help is available on. This function
     535   * returns the results back to the user. It is up to the user to
     536   * handle the returned data. If an error occurs then false is
     537   * returned with $this->error set appropiately.
     538   *
     539   * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
     540   *
     541   * SMTP CODE SUCCESS: 211,214
     542   * SMTP CODE ERROR  : 500,501,502,504,421
     543   * @access public
     544   * @return string
     545   */
     546  function Help($keyword="") {
     547    $this->error = null; # to avoid confusion
     548
     549    if(!$this->connected()) {
     550      $this->error = array(
     551              "error" => "Called Help() without being connected");
     552      return false;
     553    }
     554
     555    $extra = "";
     556    if(!empty($keyword)) {
     557      $extra = " " . $keyword;
     558    }
     559
     560    fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
     561
     562    $rply = $this->get_lines();
     563    $code = substr($rply,0,3);
     564
     565    if($this->do_debug >= 2) {
     566      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     567    }
     568
     569    if($code != 211 && $code != 214) {
     570      $this->error =
     571        array("error" => "HELP not accepted from server",
     572              "smtp_code" => $code,
     573              "smtp_msg" => substr($rply,4));
     574      if($this->do_debug >= 1) {
     575        echo "SMTP -> ERROR: " . $this->error["error"] .
     576                 ": " . $rply . $this->CRLF;
     577      }
     578      return false;
     579    }
     580
     581    return $rply;
    517582  }
    518583
     
    531596   * @return bool
    532597   */
    533   public function Mail($from) {
    534     $this->error = null; // so no confusion is caused
     598  function Mail($from) {
     599    $this->error = null; # so no confusion is caused
    535600
    536601    if(!$this->connected()) {
     
    547612
    548613    if($this->do_debug >= 2) {
    549       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     614      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    550615    }
    551616
     
    556621              "smtp_msg" => substr($rply,4));
    557622      if($this->do_debug >= 1) {
    558         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     623        echo "SMTP -> ERROR: " . $this->error["error"] .
     624                 ": " . $rply . $this->CRLF;
     625      }
     626      return false;
     627    }
     628    return true;
     629  }
     630
     631  /**
     632   * Sends the command NOOP to the SMTP server.
     633   *
     634   * Implements from rfc 821: NOOP <CRLF>
     635   *
     636   * SMTP CODE SUCCESS: 250
     637   * SMTP CODE ERROR  : 500, 421
     638   * @access public
     639   * @return bool
     640   */
     641  function Noop() {
     642    $this->error = null; # so no confusion is caused
     643
     644    if(!$this->connected()) {
     645      $this->error = array(
     646              "error" => "Called Noop() without being connected");
     647      return false;
     648    }
     649
     650    fputs($this->smtp_conn,"NOOP" . $this->CRLF);
     651
     652    $rply = $this->get_lines();
     653    $code = substr($rply,0,3);
     654
     655    if($this->do_debug >= 2) {
     656      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     657    }
     658
     659    if($code != 250) {
     660      $this->error =
     661        array("error" => "NOOP not accepted from server",
     662              "smtp_code" => $code,
     663              "smtp_msg" => substr($rply,4));
     664      if($this->do_debug >= 1) {
     665        echo "SMTP -> ERROR: " . $this->error["error"] .
     666                 ": " . $rply . $this->CRLF;
    559667      }
    560668      return false;
     
    574682   * @return bool
    575683   */
    576   public function Quit($close_on_error = true) {
    577     $this->error = null; // so there is no confusion
     684  function Quit($close_on_error=true) {
     685    $this->error = null; # so there is no confusion
    578686
    579687    if(!$this->connected()) {
     
    583691    }
    584692
    585     // send the quit command to the server
     693    # send the quit command to the server
    586694    fputs($this->smtp_conn,"quit" . $this->CRLF);
    587695
    588     // get any good-bye messages
     696    # get any good-bye messages
    589697    $byemsg = $this->get_lines();
    590698
    591699    if($this->do_debug >= 2) {
    592       echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
     700      echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
    593701    }
    594702
     
    598706    $code = substr($byemsg,0,3);
    599707    if($code != 221) {
    600       // use e as a tmp var cause Close will overwrite $this->error
     708      # use e as a tmp var cause Close will overwrite $this->error
    601709      $e = array("error" => "SMTP server rejected quit command",
    602710                 "smtp_code" => $code,
     
    604712      $rval = false;
    605713      if($this->do_debug >= 1) {
    606         echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
     714        echo "SMTP -> ERROR: " . $e["error"] . ": " .
     715                 $byemsg . $this->CRLF;
    607716      }
    608717    }
     
    627736   * @return bool
    628737   */
    629   public function Recipient($to) {
    630     $this->error = null; // so no confusion is caused
     738  function Recipient($to) {
     739    $this->error = null; # so no confusion is caused
    631740
    632741    if(!$this->connected()) {
     
    642751
    643752    if($this->do_debug >= 2) {
    644       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     753      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    645754    }
    646755
     
    651760              "smtp_msg" => substr($rply,4));
    652761      if($this->do_debug >= 1) {
    653         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     762        echo "SMTP -> ERROR: " . $this->error["error"] .
     763                 ": " . $rply . $this->CRLF;
    654764      }
    655765      return false;
     
    670780   * @return bool
    671781   */
    672   public function Reset() {
    673     $this->error = null; // so no confusion is caused
     782  function Reset() {
     783    $this->error = null; # so no confusion is caused
    674784
    675785    if(!$this->connected()) {
     
    685795
    686796    if($this->do_debug >= 2) {
    687       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     797      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    688798    }
    689799
     
    694804              "smtp_msg" => substr($rply,4));
    695805      if($this->do_debug >= 1) {
    696         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    697       }
    698       return false;
    699     }
    700 
     806        echo "SMTP -> ERROR: " . $this->error["error"] .
     807                 ": " . $rply . $this->CRLF;
     808      }
     809      return false;
     810    }
     811
     812    return true;
     813  }
     814
     815  /**
     816   * Starts a mail transaction from the email address specified in
     817   * $from. Returns true if successful or false otherwise. If True
     818   * the mail transaction is started and then one or more Recipient
     819   * commands may be called followed by a Data command. This command
     820   * will send the message to the users terminal if they are logged
     821   * in.
     822   *
     823   * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
     824   *
     825   * SMTP CODE SUCCESS: 250
     826   * SMTP CODE SUCCESS: 552,451,452
     827   * SMTP CODE SUCCESS: 500,501,502,421
     828   * @access public
     829   * @return bool
     830   */
     831  function Send($from) {
     832    $this->error = null; # so no confusion is caused
     833
     834    if(!$this->connected()) {
     835      $this->error = array(
     836              "error" => "Called Send() without being connected");
     837      return false;
     838    }
     839
     840    fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
     841
     842    $rply = $this->get_lines();
     843    $code = substr($rply,0,3);
     844
     845    if($this->do_debug >= 2) {
     846      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     847    }
     848
     849    if($code != 250) {
     850      $this->error =
     851        array("error" => "SEND not accepted from server",
     852              "smtp_code" => $code,
     853              "smtp_msg" => substr($rply,4));
     854      if($this->do_debug >= 1) {
     855        echo "SMTP -> ERROR: " . $this->error["error"] .
     856                 ": " . $rply . $this->CRLF;
     857      }
     858      return false;
     859    }
    701860    return true;
    702861  }
     
    718877   * @return bool
    719878   */
    720   public function SendAndMail($from) {
    721     $this->error = null; // so no confusion is caused
     879  function SendAndMail($from) {
     880    $this->error = null; # so no confusion is caused
    722881
    723882    if(!$this->connected()) {
     
    733892
    734893    if($this->do_debug >= 2) {
    735       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     894      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    736895    }
    737896
     
    742901              "smtp_msg" => substr($rply,4));
    743902      if($this->do_debug >= 1) {
    744         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     903        echo "SMTP -> ERROR: " . $this->error["error"] .
     904                 ": " . $rply . $this->CRLF;
     905      }
     906      return false;
     907    }
     908    return true;
     909  }
     910
     911  /**
     912   * Starts a mail transaction from the email address specified in
     913   * $from. Returns true if successful or false otherwise. If True
     914   * the mail transaction is started and then one or more Recipient
     915   * commands may be called followed by a Data command. This command
     916   * will send the message to the users terminal if they are logged
     917   * in or mail it to them if they are not.
     918   *
     919   * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
     920   *
     921   * SMTP CODE SUCCESS: 250
     922   * SMTP CODE SUCCESS: 552,451,452
     923   * SMTP CODE SUCCESS: 500,501,502,421
     924   * @access public
     925   * @return bool
     926   */
     927  function SendOrMail($from) {
     928    $this->error = null; # so no confusion is caused
     929
     930    if(!$this->connected()) {
     931      $this->error = array(
     932          "error" => "Called SendOrMail() without being connected");
     933      return false;
     934    }
     935
     936    fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
     937
     938    $rply = $this->get_lines();
     939    $code = substr($rply,0,3);
     940
     941    if($this->do_debug >= 2) {
     942      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     943    }
     944
     945    if($code != 250) {
     946      $this->error =
     947        array("error" => "SOML not accepted from server",
     948              "smtp_code" => $code,
     949              "smtp_msg" => substr($rply,4));
     950      if($this->do_debug >= 1) {
     951        echo "SMTP -> ERROR: " . $this->error["error"] .
     952                 ": " . $rply . $this->CRLF;
    745953      }
    746954      return false;
     
    762970   * @return bool
    763971   */
    764   public function Turn() {
     972  function Turn() {
    765973    $this->error = array("error" => "This method, TURN, of the SMTP ".
    766974                                    "is not implemented");
    767975    if($this->do_debug >= 1) {
    768       echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
     976      echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
    769977    }
    770978    return false;
     
    772980
    773981  /**
    774   * Get the current error
    775   * @access public
    776   * @return array
    777   */
    778   public function getError() {
    779     return $this->error;
    780   }
    781 
    782   /////////////////////////////////////////////////
    783   // INTERNAL FUNCTIONS
    784   /////////////////////////////////////////////////
     982   * Verifies that the name is recognized by the server.
     983   * Returns false if the name could not be verified otherwise
     984   * the response from the server is returned.
     985   *
     986   * Implements rfc 821: VRFY <SP> <string> <CRLF>
     987   *
     988   * SMTP CODE SUCCESS: 250,251
     989   * SMTP CODE FAILURE: 550,551,553
     990   * SMTP CODE ERROR  : 500,501,502,421
     991   * @access public
     992   * @return int
     993   */
     994  function Verify($name) {
     995    $this->error = null; # so no confusion is caused
     996
     997    if(!$this->connected()) {
     998      $this->error = array(
     999              "error" => "Called Verify() without being connected");
     1000      return false;
     1001    }
     1002
     1003    fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
     1004
     1005    $rply = $this->get_lines();
     1006    $code = substr($rply,0,3);
     1007
     1008    if($this->do_debug >= 2) {
     1009      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     1010    }
     1011
     1012    if($code != 250 && $code != 251) {
     1013      $this->error =
     1014        array("error" => "VRFY failed on name '$name'",
     1015              "smtp_code" => $code,
     1016              "smtp_msg" => substr($rply,4));
     1017      if($this->do_debug >= 1) {
     1018        echo "SMTP -> ERROR: " . $this->error["error"] .
     1019                 ": " . $rply . $this->CRLF;
     1020      }
     1021      return false;
     1022    }
     1023    return $rply;
     1024  }
     1025
     1026  /*******************************************************************
     1027   *                       INTERNAL FUNCTIONS                       *
     1028   ******************************************************************/
    7851029
    7861030  /**
     
    7931037   * @return string
    7941038   */
    795   private function get_lines() {
     1039  function get_lines() {
    7961040    $data = "";
    7971041    while($str = @fgets($this->smtp_conn,515)) {
    7981042      if($this->do_debug >= 4) {
    799         echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
    800         echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
     1043        echo "SMTP -> get_lines(): \$data was \"$data\"" .
     1044                 $this->CRLF;
     1045        echo "SMTP -> get_lines(): \$str is \"$str\"" .
     1046                 $this->CRLF;
    8011047      }
    8021048      $data .= $str;
    8031049      if($this->do_debug >= 4) {
    804         echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
    805       }
    806       // if 4th character is a space, we are done reading, break the loop
     1050        echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
     1051      }
     1052      # if the 4th character is a space then we are done reading
     1053      # so just break the loop
    8071054      if(substr($str,3,1) == " ") { break; }
    8081055    }
     
    8121059}
    8131060
    814 ?>
     1061
     1062 ?>
Note: See TracChangeset for help on using the changeset viewer.