Connected() public method

Returns true if connected to a server otherwise false
public Connected ( ) : boolean
return boolean
 function checkSMTP($smtp_server, $smtp_port = 25, $username, $password, $auth_enabled = false, $tls_enabled = true)
 {
     require_once "libs/phpmailer/class.smtp.php";
     $smtp = new SMTP();
     $smtp->Connect($smtp_server, $smtp_port);
     if (!$smtp->Connected()) {
         return array("ERROR" => "Failed to connect to server", "SMTP_ERROR" => $smtp->getError());
     }
     if (!$smtp->Hello()) {
         return array("ERROR" => "Failed to send hello command", "SMTP_ERROR" => $smtp->getError());
     }
     if ($tls_enabled) {
         if (!$smtp->StartTLS()) {
             return array("ERROR" => "Failed to start TLS", "SMTP_ERROR" => $smtp->getError());
         }
     }
     if ($auth_enabled) {
         if (!$smtp->Authenticate($username, $password)) {
             $error = $smtp->getError();
             if (preg_match("/STARTTLS/", $error['smtp_msg'])) {
                 return array("ERROR" => "Authenticate Error, TLS must be activated", "SMTP_ERROR" => $smtp->getError());
             } else {
                 return array("ERROR" => "Authenticate not accepted from server", "SMTP_ERROR" => $smtp->getError());
             }
         }
     }
     return true;
 }
示例#2
0
 public function send($para = array(), $single = false, $priority = 3, $extHeader = "")
 {
     if ($this->from == '') {
         $this->from = ini_get('sendmail_from');
     }
     $this->addHeader("Return-Path", $this->from);
     $mail_list = array_merge($this->to, $this->cc, $this->bcc);
     if ($single == false) {
         if (count($this->to) > 0) {
             $this->addHeader("To", implode(', ', $this->formatEmail($this->to)));
         }
         if (count($this->cc) > 0) {
             $this->addHeader("Cc", implode(', ', $this->formatEmail($this->cc)));
         }
         if (count($this->bcc) > 0) {
             $this->addHeader("Bcc", implode(', ', $this->formatEmail($this->bcc)));
         }
     }
     $this->addHeader("From", $this->from);
     if (count($this->reply) > 0) {
         $this->addHeader("Reply-To", implode(', ', $this->formatEmail($this->reply)));
     }
     $this->addHeader("Subject", $this->subject);
     $this->addHeader("Message-ID", sprintf("<%s@%s>", md5(uniqid(time())), $_SERVER["HTTP_HOST"]));
     if (!preg_match("/[1-5]/", $priority)) {
         $priority = 3;
     }
     $this->addHeader("X-Priority", $priority);
     $this->addHeader("X-Mailer", "MyStep_CMS");
     $this->addHeader("MIME-Version", "1.0");
     $mail_content = implode("\r\n", $this->headers) . "\r\n";
     if (!empty($extHeader)) {
         $mail_content .= $extHeader . "\r\n";
     }
     $mail_content .= $this->buildMail();
     $info = "";
     if (!empty($para['mode'])) {
         require "class.smtp.php";
         $smtp = new SMTP();
         if (!$smtp->Connect(($para['mode'] == "ssl" || $para['mode'] == "ssl/tls" ? "ssl://" : "") . $para['host'], $para['port'], 10)) {
             $this->Error("Cannot connect to the mail server!");
             return false;
         }
         if (!$smtp->Hello($_SERVER["HTTP_HOST"])) {
             $this->Error("Cannot send messege to the mail server!");
             return false;
         }
         if ($para['mode'] == "tls" || $para['mode'] == "ssl/tls") {
             if (!$smtp->StartTLS()) {
                 $this->Error("TLS error!");
                 return false;
             }
             $smtp->Hello($_SERVER["HTTP_HOST"]);
         }
         if (isset($para['user'])) {
             if (!$smtp->Authenticate($para['user'], $para['password'])) {
                 $this->Error("Authenticate Failed!");
                 return false;
             }
         }
         if (!$smtp->Mail(ini_get('sendmail_from'))) {
             $this->Error("Bad sender email");
             return false;
         }
         for ($i = 0, $m = count($mail_list); $i < $m; $i++) {
             if ($smtp->Recipient($mail_list[$i][0])) {
                 $info = " sended!";
             } else {
                 $info = " error!";
             }
             if ($this->log_fp) {
                 fwrite($this->log_fp, $mail_list[$i][0] . $info . "\n");
             }
         }
         if (!$smtp->Data($mail_content)) {
             $this->Error("Mail send Failed!");
             return false;
         }
         $smtp->Reset();
         if ($smtp->Connected()) {
             $smtp->Quit();
             $smtp->Close();
         }
     } else {
         for ($i = 0, $m = count($mail_list); $i < $m; $i++) {
             if (!@mail(formatEmail($mail_list[$i]), $this->subject, "", $mail_content)) {
                 $info = " sended!";
             } else {
                 $info = " error!";
             }
             if ($this->log_fp) {
                 fwrite($this->log_fp, $mail_list[$i][0] . $info . "\n");
             }
         }
     }
     if ($this->log_fp) {
         fclose($this->log_fp);
     }
     return true;
 }