Close() public method

It is not considered good to use this function without first trying to use QUIT.
public Close ( )
コード例 #1
0
ファイル: bipipe.php プロジェクト: nulled/nulled
<?php

include "class.smtp.php";
$fp = fopen("domains", "r");
$domains = unserialize(fread($fp, filesize("domains")));
fclose($fp);
$smtp = new SMTP();
$smtp->do_debug = 2;
foreach ($domains as $key => $value) {
    $email = $domains[$key][0];
    $mx = $domains[$key][1];
    //echo "email:$email mx:$mx\n";
    echo "--->> {$mx} <<---\n";
    $smtp->Connect($mx, 25, 30);
    $smtp->Hello("planetxmail");
    $smtp->Mail("*****@*****.**");
    $smtp->Recipient($email);
    $smtp->Data("This is only a test.");
    $smtp->Close();
    echo "--------------------\n";
}
コード例 #2
0
 /**
  * Sends mail via SMTP using PhpSMTP (Author:
  * Chris Ryan).  Returns bool.  Returns false if there is a
  * bad MAIL FROM, RCPT, or DATA input.
  * @access private
  * @return bool
  */
 function smtp_send($header, $body)
 {
     // Include SMTP class code, but not twice
     include_once $this->PluginDir . "class.smtp.php";
     $smtp = new SMTP();
     $smtp->do_debug = $this->SMTPDebug;
     // Try to connect to all SMTP servers
     $hosts = explode(";", $this->Host);
     $index = 0;
     $connection = false;
     $smtp_from = "";
     $bad_rcpt = array();
     $e = "";
     // Retry while there is no connection
     while ($index < count($hosts) && $connection == false) {
         if (strstr($hosts[$index], ":")) {
             list($host, $port) = explode(":", $hosts[$index]);
         } else {
             $host = $hosts[$index];
             $port = $this->Port;
         }
         if ($smtp->Connect($host, $port, $this->Timeout)) {
             $connection = true;
         }
         //printf("%s host could not connect<br>", $hosts[$index]); //debug only
         $index++;
     }
     if (!$connection) {
         $this->error_handler("SMTP Error: could not connect to SMTP host server(s)");
         return false;
     }
     // Must perform HELO before authentication
     if ($this->Helo != '') {
         $smtp->Hello($this->Helo);
     } else {
         $smtp->Hello($this->get_server_hostname());
     }
     // If user requests SMTP authentication
     if ($this->SMTPAuth) {
         if (!$smtp->Authenticate($this->Username, $this->Password)) {
             $this->error_handler("SMTP Error: Could not authenticate");
             return false;
         }
     }
     if ($this->Sender == "") {
         $smtp_from = $this->From;
     } else {
         $smtp_from = $this->Sender;
     }
     if (!$smtp->Mail(sprintf("<%s>", $smtp_from))) {
         $e = sprintf("SMTP Error: From address [%s] failed", $smtp_from);
         $this->error_handler($e);
         return false;
     }
     // Attempt to send attach all recipients
     for ($i = 0; $i < count($this->to); $i++) {
         if (!$smtp->Recipient(sprintf("<%s>", $this->to[$i][0]))) {
             $bad_rcpt[] = $this->to[$i][0];
         }
     }
     for ($i = 0; $i < count($this->cc); $i++) {
         if (!$smtp->Recipient(sprintf("<%s>", $this->cc[$i][0]))) {
             $bad_rcpt[] = $this->cc[$i][0];
         }
     }
     for ($i = 0; $i < count($this->bcc); $i++) {
         if (!$smtp->Recipient(sprintf("<%s>", $this->bcc[$i][0]))) {
             $bad_rcpt[] = $this->bcc[$i][0];
         }
     }
     // Create error message
     if (count($bad_rcpt) > 0) {
         for ($i = 0; $i < count($bad_rcpt); $i++) {
             if ($i != 0) {
                 $e .= ", ";
             }
             $e .= $bad_rcpt[$i];
         }
         $e = sprintf("SMTP Error: The following recipients failed [%s]", $e);
         $this->error_handler($e);
         return false;
     }
     if (!$smtp->Data(sprintf("%s%s", $header, $body))) {
         $this->error_handler("SMTP Error: Data not accepted");
         return false;
     }
     $smtp->Quit();
     $smtp->Close();
     return true;
 }
コード例 #3
0
ファイル: myemail.class.php プロジェクト: laiello/mystep-cms
 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;
 }