You are here

function SMTP::Quit in SMTP Authentication Support 5

Same name and namespace in other branches
  1. 7.2 smtp.transport.inc \SMTP::Quit()
  2. 7 smtp.transport.inc \SMTP::Quit()

Sends the quit command to the server and then closes the socket if there is no error or the $close_on_error argument is true.

Implements from rfc 821: QUIT <CRLF>

SMTP CODE SUCCESS: 221 SMTP CODE ERROR : 500 @access public

Return value

bool

File

./smtp.module, line 2640
Enables drupal to send email directly to an SMTP server using authentication. Uses the PHPMailer class by Brent R. Matzelle.

Class

SMTP
SMTP is rfc 821 compliant and implements all the rfc 821 SMTP commands except TURN which will always return a not implemented error. SMTP also provides some utility methods for sending mail to an SMTP server. @package PHPMailer @author Chris Ryan

Code

function Quit($close_on_error = true) {
  $this->error = null;

  # so there is no confusion
  if (!$this
    ->connected()) {
    $this->error = array(
      "error" => "Called Quit() without being connected",
    );
    return false;
  }

  # send the quit command to the server
  fputs($this->smtp_conn, "quit" . $this->CRLF);

  # get any good-bye messages
  $byemsg = $this
    ->get_lines();
  if ($this->do_debug >= 2) {
    echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
  }
  $rval = true;
  $e = null;
  $code = substr($byemsg, 0, 3);
  if ($code != 221) {

    # use e as a tmp var cause Close will overwrite $this->error
    $e = array(
      "error" => "SMTP server rejected quit command",
      "smtp_code" => $code,
      "smtp_rply" => substr($byemsg, 4),
    );
    $rval = false;
    if ($this->do_debug >= 1) {
      echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF;
    }
  }
  if (empty($e) || $close_on_error) {
    $this
      ->Close();
  }
  return $rval;
}