root@9: smtp_conn = 0;
root@9: $this->error = null;
root@9: $this->helo_rply = null;
root@9:
root@9: $this->do_debug = 0;
root@9: }
root@9:
root@9: /////////////////////////////////////////////////
root@9: // CONNECTION FUNCTIONS
root@9: /////////////////////////////////////////////////
root@9:
root@9: /**
root@9: * Connect to the server specified on the port specified.
root@9: * If the port is not specified use the default SMTP_PORT.
root@9: * If tval is specified then a connection will try and be
root@9: * established with the server for that number of seconds.
root@9: * If tval is not specified the default is 30 seconds to
root@9: * try on the connection.
root@9: *
root@9: * SMTP CODE SUCCESS: 220
root@9: * SMTP CODE FAILURE: 421
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Connect($host, $port = 0, $tval = 30) {
root@9: // set the error val to null so there is no confusion
root@9: $this->error = null;
root@9:
root@9: // make sure we are __not__ connected
root@9: if($this->connected()) {
root@9: // already connected, generate error
root@9: $this->error = array("error" => "Already connected to a server");
root@9: return false;
root@9: }
root@9:
root@9: if(empty($port)) {
root@9: $port = $this->SMTP_PORT;
root@9: }
root@9:
root@9: // connect to the smtp server
root@9: $this->smtp_conn = @fsockopen($host, // the host of the server
root@9: $port, // the port to use
root@9: $errno, // error number if any
root@9: $errstr, // error message if any
root@9: $tval); // give up after ? secs
root@9: // verify we connected properly
root@9: if(empty($this->smtp_conn)) {
root@9: $this->error = array("error" => "Failed to connect to server",
root@9: "errno" => $errno,
root@9: "errstr" => $errstr);
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: // SMTP server can take longer to respond, give longer timeout for first read
root@9: // Windows does not have support for this timeout function
root@9: if(substr(PHP_OS, 0, 3) != "WIN")
root@9: socket_set_timeout($this->smtp_conn, $tval, 0);
root@9:
root@9: // get any announcement
root@9: $announce = $this->get_lines();
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '
';
root@9: }
root@9:
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Initiate a TLS communication with the server.
root@9: *
root@9: * SMTP CODE 220 Ready to start TLS
root@9: * SMTP CODE 501 Syntax error (no parameters allowed)
root@9: * SMTP CODE 454 TLS not available due to temporary reason
root@9: * @access public
root@9: * @return bool success
root@9: */
root@9: public function StartTLS() {
root@9: $this->error = null; # to avoid confusion
root@9:
root@9: if(!$this->connected()) {
root@9: $this->error = array("error" => "Called StartTLS() without being connected");
root@9: return false;
root@9: }
root@9:
root@9: fputs($this->smtp_conn,"STARTTLS" . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
root@9: }
root@9:
root@9: if($code != 220) {
root@9: $this->error =
root@9: array("error" => "STARTTLS not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: // Begin encrypted connection
root@9: if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
root@9: return false;
root@9: }
root@9:
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Performs SMTP authentication. Must be run after running the
root@9: * Hello() method. Returns true if successfully authenticated.
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Authenticate($username, $password) {
root@9: // Start authentication
root@9: fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($code != 334) {
root@9: $this->error =
root@9: array("error" => "AUTH not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: // Send encoded username
root@9: fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($code != 334) {
root@9: $this->error =
root@9: array("error" => "Username not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: // Send encoded password
root@9: fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($code != 235) {
root@9: $this->error =
root@9: array("error" => "Password not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Returns true if connected to a server otherwise false
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Connected() {
root@9: if(!empty($this->smtp_conn)) {
root@9: $sock_status = socket_get_status($this->smtp_conn);
root@9: if($sock_status["eof"]) {
root@9: // the socket is valid but we are not connected
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
root@9: }
root@9: $this->Close();
root@9: return false;
root@9: }
root@9: return true; // everything looks good
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: /**
root@9: * Closes the socket and cleans up the state of the class.
root@9: * It is not considered good to use this function without
root@9: * first trying to use QUIT.
root@9: * @access public
root@9: * @return void
root@9: */
root@9: public function Close() {
root@9: $this->error = null; // so there is no confusion
root@9: $this->helo_rply = null;
root@9: if(!empty($this->smtp_conn)) {
root@9: // close the connection and cleanup
root@9: fclose($this->smtp_conn);
root@9: $this->smtp_conn = 0;
root@9: }
root@9: }
root@9:
root@9: /////////////////////////////////////////////////
root@9: // SMTP COMMANDS
root@9: /////////////////////////////////////////////////
root@9:
root@9: /**
root@9: * Issues a data command and sends the msg_data to the server
root@9: * finializing the mail transaction. $msg_data is the message
root@9: * that is to be send with the headers. Each header needs to be
root@9: * on a single line followed by a with the message headers
root@9: * and the message body being seperated by and additional .
root@9: *
root@9: * Implements rfc 821: DATA
root@9: *
root@9: * SMTP CODE INTERMEDIATE: 354
root@9: * [data]
root@9: * .
root@9: * SMTP CODE SUCCESS: 250
root@9: * SMTP CODE FAILURE: 552,554,451,452
root@9: * SMTP CODE FAILURE: 451,554
root@9: * SMTP CODE ERROR : 500,501,503,421
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Data($msg_data) {
root@9: $this->error = null; // so no confusion is caused
root@9:
root@9: if(!$this->connected()) {
root@9: $this->error = array(
root@9: "error" => "Called Data() without being connected");
root@9: return false;
root@9: }
root@9:
root@9: fputs($this->smtp_conn,"DATA" . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
root@9: }
root@9:
root@9: if($code != 354) {
root@9: $this->error =
root@9: array("error" => "DATA command not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: /* the server is ready to accept data!
root@9: * according to rfc 821 we should not send more than 1000
root@9: * including the CRLF
root@9: * characters on a single line so we will break the data up
root@9: * into lines by \r and/or \n then if needed we will break
root@9: * each of those into smaller lines to fit within the limit.
root@9: * in addition we will be looking for lines that start with
root@9: * a period '.' and append and additional period '.' to that
root@9: * line. NOTE: this does not count towards limit.
root@9: */
root@9:
root@9: // normalize the line breaks so we know the explode works
root@9: $msg_data = str_replace("\r\n","\n",$msg_data);
root@9: $msg_data = str_replace("\r","\n",$msg_data);
root@9: $lines = explode("\n",$msg_data);
root@9:
root@9: /* we need to find a good way to determine is headers are
root@9: * in the msg_data or if it is a straight msg body
root@9: * currently I am assuming rfc 822 definitions of msg headers
root@9: * and if the first field of the first line (':' sperated)
root@9: * does not contain a space then it _should_ be a header
root@9: * and we can process all lines before a blank "" line as
root@9: * headers.
root@9: */
root@9:
root@9: $field = substr($lines[0],0,strpos($lines[0],":"));
root@9: $in_headers = false;
root@9: if(!empty($field) && !strstr($field," ")) {
root@9: $in_headers = true;
root@9: }
root@9:
root@9: $max_line_length = 998; // used below; set here for ease in change
root@9:
root@9: while(list(,$line) = @each($lines)) {
root@9: $lines_out = null;
root@9: if($line == "" && $in_headers) {
root@9: $in_headers = false;
root@9: }
root@9: // ok we need to break this line up into several smaller lines
root@9: while(strlen($line) > $max_line_length) {
root@9: $pos = strrpos(substr($line,0,$max_line_length)," ");
root@9:
root@9: // Patch to fix DOS attack
root@9: if(!$pos) {
root@9: $pos = $max_line_length - 1;
root@9: $lines_out[] = substr($line,0,$pos);
root@9: $line = substr($line,$pos);
root@9: } else {
root@9: $lines_out[] = substr($line,0,$pos);
root@9: $line = substr($line,$pos + 1);
root@9: }
root@9:
root@9: /* if processing headers add a LWSP-char to the front of new line
root@9: * rfc 822 on long msg headers
root@9: */
root@9: if($in_headers) {
root@9: $line = "\t" . $line;
root@9: }
root@9: }
root@9: $lines_out[] = $line;
root@9:
root@9: // send the lines to the server
root@9: while(list(,$line_out) = @each($lines_out)) {
root@9: if(strlen($line_out) > 0)
root@9: {
root@9: if(substr($line_out, 0, 1) == ".") {
root@9: $line_out = "." . $line_out;
root@9: }
root@9: }
root@9: fputs($this->smtp_conn,$line_out . $this->CRLF);
root@9: }
root@9: }
root@9:
root@9: // message data has been sent
root@9: fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
root@9: }
root@9:
root@9: if($code != 250) {
root@9: $this->error =
root@9: array("error" => "DATA not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Sends the HELO command to the smtp server.
root@9: * This makes sure that we and the server are in
root@9: * the same known state.
root@9: *
root@9: * Implements from rfc 821: HELO
root@9: *
root@9: * SMTP CODE SUCCESS: 250
root@9: * SMTP CODE ERROR : 500, 501, 504, 421
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Hello($host = '') {
root@9: $this->error = null; // so no confusion is caused
root@9:
root@9: if(!$this->connected()) {
root@9: $this->error = array(
root@9: "error" => "Called Hello() without being connected");
root@9: return false;
root@9: }
root@9:
root@9: // if hostname for HELO was not specified send default
root@9: if(empty($host)) {
root@9: // determine appropriate default to send to server
root@9: $host = "localhost";
root@9: }
root@9:
root@9: // Send extended hello first (RFC 2821)
root@9: if(!$this->SendHello("EHLO", $host)) {
root@9: if(!$this->SendHello("HELO", $host)) {
root@9: return false;
root@9: }
root@9: }
root@9:
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Sends a HELO/EHLO command.
root@9: * @access private
root@9: * @return bool
root@9: */
root@9: private function SendHello($hello, $host) {
root@9: fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '
';
root@9: }
root@9:
root@9: if($code != 250) {
root@9: $this->error =
root@9: array("error" => $hello . " not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: $this->helo_rply = $rply;
root@9:
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Starts a mail transaction from the email address specified in
root@9: * $from. Returns true if successful or false otherwise. If True
root@9: * the mail transaction is started and then one or more Recipient
root@9: * commands may be called followed by a Data command.
root@9: *
root@9: * Implements rfc 821: MAIL FROM:
root@9: *
root@9: * SMTP CODE SUCCESS: 250
root@9: * SMTP CODE SUCCESS: 552,451,452
root@9: * SMTP CODE SUCCESS: 500,501,421
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Mail($from) {
root@9: $this->error = null; // so no confusion is caused
root@9:
root@9: if(!$this->connected()) {
root@9: $this->error = array(
root@9: "error" => "Called Mail() without being connected");
root@9: return false;
root@9: }
root@9:
root@9: $useVerp = ($this->do_verp ? "XVERP" : "");
root@9: fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
root@9: }
root@9:
root@9: if($code != 250) {
root@9: $this->error =
root@9: array("error" => "MAIL not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Sends the quit command to the server and then closes the socket
root@9: * if there is no error or the $close_on_error argument is true.
root@9: *
root@9: * Implements from rfc 821: QUIT
root@9: *
root@9: * SMTP CODE SUCCESS: 221
root@9: * SMTP CODE ERROR : 500
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Quit($close_on_error = true) {
root@9: $this->error = null; // so there is no confusion
root@9:
root@9: if(!$this->connected()) {
root@9: $this->error = array(
root@9: "error" => "Called Quit() without being connected");
root@9: return false;
root@9: }
root@9:
root@9: // send the quit command to the server
root@9: fputs($this->smtp_conn,"quit" . $this->CRLF);
root@9:
root@9: // get any good-bye messages
root@9: $byemsg = $this->get_lines();
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '
';
root@9: }
root@9:
root@9: $rval = true;
root@9: $e = null;
root@9:
root@9: $code = substr($byemsg,0,3);
root@9: if($code != 221) {
root@9: // use e as a tmp var cause Close will overwrite $this->error
root@9: $e = array("error" => "SMTP server rejected quit command",
root@9: "smtp_code" => $code,
root@9: "smtp_rply" => substr($byemsg,4));
root@9: $rval = false;
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '
';
root@9: }
root@9: }
root@9:
root@9: if(empty($e) || $close_on_error) {
root@9: $this->Close();
root@9: }
root@9:
root@9: return $rval;
root@9: }
root@9:
root@9: /**
root@9: * Sends the command RCPT to the SMTP server with the TO: argument of $to.
root@9: * Returns true if the recipient was accepted false if it was rejected.
root@9: *
root@9: * Implements from rfc 821: RCPT TO:
root@9: *
root@9: * SMTP CODE SUCCESS: 250,251
root@9: * SMTP CODE FAILURE: 550,551,552,553,450,451,452
root@9: * SMTP CODE ERROR : 500,501,503,421
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Recipient($to) {
root@9: $this->error = null; // so no confusion is caused
root@9:
root@9: if(!$this->connected()) {
root@9: $this->error = array(
root@9: "error" => "Called Recipient() without being connected");
root@9: return false;
root@9: }
root@9:
root@9: fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
root@9: }
root@9:
root@9: if($code != 250 && $code != 251) {
root@9: $this->error =
root@9: array("error" => "RCPT not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Sends the RSET command to abort and transaction that is
root@9: * currently in progress. Returns true if successful false
root@9: * otherwise.
root@9: *
root@9: * Implements rfc 821: RSET
root@9: *
root@9: * SMTP CODE SUCCESS: 250
root@9: * SMTP CODE ERROR : 500,501,504,421
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Reset() {
root@9: $this->error = null; // so no confusion is caused
root@9:
root@9: if(!$this->connected()) {
root@9: $this->error = array(
root@9: "error" => "Called Reset() without being connected");
root@9: return false;
root@9: }
root@9:
root@9: fputs($this->smtp_conn,"RSET" . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
root@9: }
root@9:
root@9: if($code != 250) {
root@9: $this->error =
root@9: array("error" => "RSET failed",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * Starts a mail transaction from the email address specified in
root@9: * $from. Returns true if successful or false otherwise. If True
root@9: * the mail transaction is started and then one or more Recipient
root@9: * commands may be called followed by a Data command. This command
root@9: * will send the message to the users terminal if they are logged
root@9: * in and send them an email.
root@9: *
root@9: * Implements rfc 821: SAML FROM:
root@9: *
root@9: * SMTP CODE SUCCESS: 250
root@9: * SMTP CODE SUCCESS: 552,451,452
root@9: * SMTP CODE SUCCESS: 500,501,502,421
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function SendAndMail($from) {
root@9: $this->error = null; // so no confusion is caused
root@9:
root@9: if(!$this->connected()) {
root@9: $this->error = array(
root@9: "error" => "Called SendAndMail() without being connected");
root@9: return false;
root@9: }
root@9:
root@9: fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
root@9:
root@9: $rply = $this->get_lines();
root@9: $code = substr($rply,0,3);
root@9:
root@9: if($this->do_debug >= 2) {
root@9: echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
root@9: }
root@9:
root@9: if($code != 250) {
root@9: $this->error =
root@9: array("error" => "SAML not accepted from server",
root@9: "smtp_code" => $code,
root@9: "smtp_msg" => substr($rply,4));
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9: return true;
root@9: }
root@9:
root@9: /**
root@9: * This is an optional command for SMTP that this class does not
root@9: * support. This method is here to make the RFC821 Definition
root@9: * complete for this class and __may__ be implimented in the future
root@9: *
root@9: * Implements from rfc 821: TURN
root@9: *
root@9: * SMTP CODE SUCCESS: 250
root@9: * SMTP CODE FAILURE: 502
root@9: * SMTP CODE ERROR : 500, 503
root@9: * @access public
root@9: * @return bool
root@9: */
root@9: public function Turn() {
root@9: $this->error = array("error" => "This method, TURN, of the SMTP ".
root@9: "is not implemented");
root@9: if($this->do_debug >= 1) {
root@9: echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '
';
root@9: }
root@9: return false;
root@9: }
root@9:
root@9: /**
root@9: * Get the current error
root@9: * @access public
root@9: * @return array
root@9: */
root@9: public function getError() {
root@9: return $this->error;
root@9: }
root@9:
root@9: /////////////////////////////////////////////////
root@9: // INTERNAL FUNCTIONS
root@9: /////////////////////////////////////////////////
root@9:
root@9: /**
root@9: * Read in as many lines as possible
root@9: * either before eof or socket timeout occurs on the operation.
root@9: * With SMTP we can tell if we have more lines to read if the
root@9: * 4th character is '-' symbol. If it is a space then we don't
root@9: * need to read anything else.
root@9: * @access private
root@9: * @return string
root@9: */
root@9: private function get_lines() {
root@9: $data = "";
root@9: while($str = @fgets($this->smtp_conn,515)) {
root@9: if($this->do_debug >= 4) {
root@9: echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '
';
root@9: echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '
';
root@9: }
root@9: $data .= $str;
root@9: if($this->do_debug >= 4) {
root@9: echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '
';
root@9: }
root@9: // if 4th character is a space, we are done reading, break the loop
root@9: if(substr($str,3,1) == " ") { break; }
root@9: }
root@9: return $data;
root@9: }
root@9:
root@9: }
root@9:
root@9: ?>