You are here

public function SMTP::SendAndMail in SMTP Authentication Support 7

Same name and namespace in other branches
  1. 5 smtp.module \SMTP::SendAndMail()
  2. 7.2 smtp.transport.inc \SMTP::SendAndMail()

Starts a mail transaction from the email address specified in $from. Returns TRUE if successful or FALSE otherwise. If True the mail transaction is started and then one or more Recipient commands may be called followed by a Data command. This command will send the message to the users terminal if they are logged in and send them an email.

Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>

SMTP CODE SUCCESS: 250 SMTP CODE SUCCESS: 552,451,452 SMTP CODE SUCCESS: 500,501,502,421 @access public

Return value

bool

File

./smtp.transport.inc, line 762
SMTP mail transport class for the smtp module,based on code of the phpmailer library, customized and relicensed to GPLv2

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. original author: Chris Ryan

Code

public function SendAndMail($from) {
  $this->error = NULL;

  // so no confusion is caused
  if (!$this
    ->connected()) {
    $this->error = array(
      "error" => "Called SendAndMail() without being connected",
    );
    return FALSE;
  }
  fputs($this->smtp_conn, "SAML FROM:" . $from . $this->CRLF);
  $rply = $this
    ->get_lines();
  $code = substr($rply, 0, 3);
  if ($this->do_debug >= 2) {
    drupal_set_message(t("SMTP -> FROM SERVER: @rply", array(
      "@rply" => $rply,
    )));
  }
  if ($code != 250) {
    $this->error = array(
      "error" => "SAML not accepted from server",
      "smtp_code" => $code,
      "smtp_msg" => substr($rply, 4),
    );
    if ($this->do_debug >= 1) {
      drupal_set_message(t("SMTP -> ERROR: @error: @rply", array(
        "@error" => $this->error["error"],
        "@rply" => $rply,
      )));
    }
    return FALSE;
  }
  return TRUE;
}