Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r13425 r17676  
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 2.0.4                                                          |
     5|   Version: 5.1                                                            |
    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 |    Author: Andy Prevost (project admininistrator)                         |
    11 |    Author: Brent R. Matzelle (original founder)                           |
    12 | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved.               |
     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.               |
    1315| Copyright (c) 2001-2003, Brent R. Matzelle                                |
    1416| ------------------------------------------------------------------------- |
     
    2426| - Oursourcing (highly qualified programmers and graphic designers)        |
    2527'---------------------------------------------------------------------------'
     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 $
    2639 */
     40
    2741/**
    2842 * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
     
    3044 * error. SMTP also provides some utility methods for sending mail
    3145 * to an SMTP server.
    32  * @package PHPMailer
    33  * @author Chris Ryan
     46 * original author: Chris Ryan
    3447 */
    3548
    36 class SMTP
    37 {
     49class SMTP {
    3850  /**
    3951   *  SMTP server port
    4052   *  @var int
    4153   */
    42   var $SMTP_PORT = 25;
     54  public $SMTP_PORT = 25;
    4355
    4456  /**
     
    4658   *  @var string
    4759   */
    48   var $CRLF = "\r\n";
     60  public $CRLF = "\r\n";
    4961
    5062  /**
     
    5264   *  @var bool
    5365   */
    54   var $do_debug;       # the level of debug to perform
     66  public $do_debug;       // the level of debug to perform
    5567
    5668  /**
     
    5870   *  @var bool
    5971   */
    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   /**#@-*/
     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
    6981
    7082  /**
     
    7385   * @return void
    7486   */
    75   function SMTP() {
     87  public function __construct() {
    7688    $this->smtp_conn = 0;
    7789    $this->error = null;
     
    8193  }
    8294
    83   /*************************************************************
    84    *                    CONNECTION FUNCTIONS                  *
    85    ***********************************************************/
     95  /////////////////////////////////////////////////
     96  // CONNECTION FUNCTIONS
     97  /////////////////////////////////////////////////
    8698
    8799  /**
     
    98110   * @return bool
    99111   */
    100   function Connect($host,$port=0,$tval=30) {
    101     # set the error val to null so there is no confusion
     112  public function Connect($host, $port = 0, $tval = 30) {
     113    // set the error val to null so there is no confusion
    102114    $this->error = null;
    103115
    104     # make sure we are __not__ connected
     116    // make sure we are __not__ connected
    105117    if($this->connected()) {
    106       # ok we are connected! what should we do?
    107       # for now we will just give an error saying we
    108       # are already connected
     118      // already connected, generate error
    109119      $this->error = array("error" => "Already connected to a server");
    110120      return false;
     
    115125    }
    116126
    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
     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
    124134    if(empty($this->smtp_conn)) {
    125135      $this->error = array("error" => "Failed to connect to server",
     
    127137                           "errstr" => $errstr);
    128138      if($this->do_debug >= 1) {
    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
     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
    138146    if(substr(PHP_OS, 0, 3) != "WIN")
    139147     socket_set_timeout($this->smtp_conn, $tval, 0);
    140148
    141     # get any announcement stuff
     149    // get any announcement
    142150    $announce = $this->get_lines();
    143151
    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;
     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;
    150199    }
    151200
     
    159208   * @return bool
    160209   */
    161   function Authenticate($username, $password) {
     210  public function Authenticate($username, $password) {
    162211    // Start authentication
    163212    fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
     
    172221              "smtp_msg" => substr($rply,4));
    173222      if($this->do_debug >= 1) {
    174         echo "SMTP -> ERROR: " . $this->error["error"] .
    175                  ": " . $rply . $this->CRLF;
     223        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    176224      }
    177225      return false;
     
    190238              "smtp_msg" => substr($rply,4));
    191239      if($this->do_debug >= 1) {
    192         echo "SMTP -> ERROR: " . $this->error["error"] .
    193                  ": " . $rply . $this->CRLF;
     240        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    194241      }
    195242      return false;
     
    208255              "smtp_msg" => substr($rply,4));
    209256      if($this->do_debug >= 1) {
    210         echo "SMTP -> ERROR: " . $this->error["error"] .
    211                  ": " . $rply . $this->CRLF;
     257        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    212258      }
    213259      return false;
     
    219265  /**
    220266   * Returns true if connected to a server otherwise false
    221    * @access private
    222    * @return bool
    223    */
    224   function Connected() {
     267   * @access public
     268   * @return bool
     269   */
     270  public function Connected() {
    225271    if(!empty($this->smtp_conn)) {
    226272      $sock_status = socket_get_status($this->smtp_conn);
    227273      if($sock_status["eof"]) {
    228         # hmm this is an odd situation... the socket is
    229         # valid but we are not connected anymore
     274        // the socket is valid but we are not connected
    230275        if($this->do_debug >= 1) {
    231             echo "SMTP -> NOTICE:" . $this->CRLF .
    232                  "EOF caught while checking if connected";
     276            echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
    233277        }
    234278        $this->Close();
    235279        return false;
    236280      }
    237       return true; # everything looks good
     281      return true; // everything looks good
    238282    }
    239283    return false;
     
    247291   * @return void
    248292   */
    249   function Close() {
    250     $this->error = null; # so there is no confusion
     293  public function Close() {
     294    $this->error = null; // so there is no confusion
    251295    $this->helo_rply = null;
    252296    if(!empty($this->smtp_conn)) {
    253       # close the connection and cleanup
     297      // close the connection and cleanup
    254298      fclose($this->smtp_conn);
    255299      $this->smtp_conn = 0;
     
    257301  }
    258302
    259   /***************************************************************
    260    *                        SMTP COMMANDS                       *
    261    *************************************************************/
     303  /////////////////////////////////////////////////
     304  // SMTP COMMANDS
     305  /////////////////////////////////////////////////
    262306
    263307  /**
     
    266310   * that is to be send with the headers. Each header needs to be
    267311   * on a single line followed by a <CRLF> with the message headers
    268    * and the message body being separated by and additional <CRLF>.
     312   * and the message body being seperated by and additional <CRLF>.
    269313   *
    270314   * Implements rfc 821: DATA <CRLF>
     
    280324   * @return bool
    281325   */
    282   function Data($msg_data) {
    283     $this->error = null; # so no confusion is caused
     326  public function Data($msg_data) {
     327    $this->error = null; // so no confusion is caused
    284328
    285329    if(!$this->connected()) {
     
    295339
    296340    if($this->do_debug >= 2) {
    297       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     341      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
    298342    }
    299343
     
    304348              "smtp_msg" => substr($rply,4));
    305349      if($this->do_debug >= 1) {
    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
     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
    323367    $msg_data = str_replace("\r\n","\n",$msg_data);
    324368    $msg_data = str_replace("\r","\n",$msg_data);
    325369    $lines = explode("\n",$msg_data);
    326370
    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.
     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
    334380    $field = substr($lines[0],0,strpos($lines[0],":"));
    335381    $in_headers = false;
     
    338384    }
    339385
    340     $max_line_length = 998; # used below; set here for ease in change
     386    $max_line_length = 998; // used below; set here for ease in change
    341387
    342388    while(list(,$line) = @each($lines)) {
     
    345391        $in_headers = false;
    346392      }
    347       # ok we need to break this line up into several
    348       # smaller lines
     393      // ok we need to break this line up into several smaller lines
    349394      while(strlen($line) > $max_line_length) {
    350395        $pos = strrpos(substr($line,0,$max_line_length)," ");
    351396
    352         # Patch to fix DOS attack
     397        // Patch to fix DOS attack
    353398        if(!$pos) {
    354399          $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);
    355405        }
    356406
    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
     407        /* if processing headers add a LWSP-char to the front of new line
     408         * rfc 822 on long msg headers
     409         */
    362410        if($in_headers) {
    363411          $line = "\t" . $line;
     
    366414      $lines_out[] = $line;
    367415
    368       # now send the lines to the server
     416      // send the lines to the server
    369417      while(list(,$line_out) = @each($lines_out)) {
    370418        if(strlen($line_out) > 0)
     
    378426    }
    379427
    380     # ok all the message data has been sent so lets get this
    381     # over with aleady
     428    // message data has been sent
    382429    fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
    383430
     
    386433
    387434    if($this->do_debug >= 2) {
    388       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     435      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
    389436    }
    390437
     
    395442              "smtp_msg" => substr($rply,4));
    396443      if($this->do_debug >= 1) {
    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;
     444        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     445      }
     446      return false;
     447    }
     448    return true;
    458449  }
    459450
     
    470461   * @return bool
    471462   */
    472   function Hello($host="") {
    473     $this->error = null; # so no confusion is caused
     463  public function Hello($host = '') {
     464    $this->error = null; // so no confusion is caused
    474465
    475466    if(!$this->connected()) {
     
    479470    }
    480471
    481     # if a hostname for the HELO was not specified determine
    482     # a suitable one to send
     472    // if hostname for HELO was not specified send default
    483473    if(empty($host)) {
    484       # we need to determine some sort of appopiate default
    485       # to send to the server
     474      // determine appropriate default to send to server
    486475      $host = "localhost";
    487476    }
    488477
    489478    // Send extended hello first (RFC 2821)
    490     if(!$this->SendHello("EHLO", $host))
    491     {
    492       if(!$this->SendHello("HELO", $host))
    493           return false;
     479    if(!$this->SendHello("EHLO", $host)) {
     480      if(!$this->SendHello("HELO", $host)) {
     481        return false;
     482      }
    494483    }
    495484
     
    502491   * @return bool
    503492   */
    504   function SendHello($hello, $host) {
     493  private function SendHello($hello, $host) {
    505494    fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
    506495
     
    509498
    510499    if($this->do_debug >= 2) {
    511       echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
     500      echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
    512501    }
    513502
     
    518507              "smtp_msg" => substr($rply,4));
    519508      if($this->do_debug >= 1) {
    520         echo "SMTP -> ERROR: " . $this->error["error"] .
    521                  ": " . $rply . $this->CRLF;
     509        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    522510      }
    523511      return false;
     
    527515
    528516    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;
    582517  }
    583518
     
    596531   * @return bool
    597532   */
    598   function Mail($from) {
    599     $this->error = null; # so no confusion is caused
     533  public function Mail($from) {
     534    $this->error = null; // so no confusion is caused
    600535
    601536    if(!$this->connected()) {
     
    612547
    613548    if($this->do_debug >= 2) {
    614       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     549      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
    615550    }
    616551
     
    621556              "smtp_msg" => substr($rply,4));
    622557      if($this->do_debug >= 1) {
    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;
     558        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    667559      }
    668560      return false;
     
    682574   * @return bool
    683575   */
    684   function Quit($close_on_error=true) {
    685     $this->error = null; # so there is no confusion
     576  public function Quit($close_on_error = true) {
     577    $this->error = null; // so there is no confusion
    686578
    687579    if(!$this->connected()) {
     
    691583    }
    692584
    693     # send the quit command to the server
     585    // send the quit command to the server
    694586    fputs($this->smtp_conn,"quit" . $this->CRLF);
    695587
    696     # get any good-bye messages
     588    // get any good-bye messages
    697589    $byemsg = $this->get_lines();
    698590
    699591    if($this->do_debug >= 2) {
    700       echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
     592      echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
    701593    }
    702594
     
    706598    $code = substr($byemsg,0,3);
    707599    if($code != 221) {
    708       # use e as a tmp var cause Close will overwrite $this->error
     600      // use e as a tmp var cause Close will overwrite $this->error
    709601      $e = array("error" => "SMTP server rejected quit command",
    710602                 "smtp_code" => $code,
     
    712604      $rval = false;
    713605      if($this->do_debug >= 1) {
    714         echo "SMTP -> ERROR: " . $e["error"] . ": " .
    715                  $byemsg . $this->CRLF;
     606        echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
    716607      }
    717608    }
     
    736627   * @return bool
    737628   */
    738   function Recipient($to) {
    739     $this->error = null; # so no confusion is caused
     629  public function Recipient($to) {
     630    $this->error = null; // so no confusion is caused
    740631
    741632    if(!$this->connected()) {
     
    751642
    752643    if($this->do_debug >= 2) {
    753       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     644      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
    754645    }
    755646
     
    760651              "smtp_msg" => substr($rply,4));
    761652      if($this->do_debug >= 1) {
    762         echo "SMTP -> ERROR: " . $this->error["error"] .
    763                  ": " . $rply . $this->CRLF;
     653        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    764654      }
    765655      return false;
     
    780670   * @return bool
    781671   */
    782   function Reset() {
    783     $this->error = null; # so no confusion is caused
     672  public function Reset() {
     673    $this->error = null; // so no confusion is caused
    784674
    785675    if(!$this->connected()) {
     
    795685
    796686    if($this->do_debug >= 2) {
    797       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     687      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
    798688    }
    799689
     
    804694              "smtp_msg" => substr($rply,4));
    805695      if($this->do_debug >= 1) {
    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     }
     696        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     697      }
     698      return false;
     699    }
     700
    860701    return true;
    861702  }
     
    877718   * @return bool
    878719   */
    879   function SendAndMail($from) {
    880     $this->error = null; # so no confusion is caused
     720  public function SendAndMail($from) {
     721    $this->error = null; // so no confusion is caused
    881722
    882723    if(!$this->connected()) {
     
    892733
    893734    if($this->do_debug >= 2) {
    894       echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     735      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
    895736    }
    896737
     
    901742              "smtp_msg" => substr($rply,4));
    902743      if($this->do_debug >= 1) {
    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;
     744        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    953745      }
    954746      return false;
     
    970762   * @return bool
    971763   */
    972   function Turn() {
     764  public function Turn() {
    973765    $this->error = array("error" => "This method, TURN, of the SMTP ".
    974766                                    "is not implemented");
    975767    if($this->do_debug >= 1) {
    976       echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
     768      echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
    977769    }
    978770    return false;
     
    980772
    981773  /**
    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    ******************************************************************/
     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  /////////////////////////////////////////////////
    1029785
    1030786  /**
     
    1037793   * @return string
    1038794   */
    1039   function get_lines() {
     795  private function get_lines() {
    1040796    $data = "";
    1041797    while($str = @fgets($this->smtp_conn,515)) {
    1042798      if($this->do_debug >= 4) {
    1043         echo "SMTP -> get_lines(): \$data was \"$data\"" .
    1044                  $this->CRLF;
    1045         echo "SMTP -> get_lines(): \$str is \"$str\"" .
    1046                  $this->CRLF;
     799        echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
     800        echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
    1047801      }
    1048802      $data .= $str;
    1049803      if($this->do_debug >= 4) {
    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
     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
    1054807      if(substr($str,3,1) == " ") { break; }
    1055808    }
     
    1059812}
    1060813
    1061 
    1062  ?>
     814?>
Note: See TracChangeset for help on using the changeset viewer.