⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.smtp.php

📁 public class phpmailer phpmailer - PHP email transport cla
💻 PHP
📖 第 1 页 / 共 3 页
字号:
         * Recipient($to)
         *
         * Sends the command RCPT to the SMTP server with the TO: argument of $to.
         * Returns true if the recipient was accepted false if it was rejected.
         *
         * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
         *
         * SMTP CODE SUCCESS: 250,251
         * SMTP CODE FAILURE: 550,551,552,553,450,451,452
         * SMTP CODE ERROR  : 500,501,503,421
         */
        function Recipient($to) {
            $this->error = null; # so no confusion is caused

            if(!$this->connected()) {
                $this->error = array(
                        "error" => "Called Recipient() without being connected");
                return false;
            }

            fputs($this->smtp_conn,"RCPT TO:" . $to . $this->CRLF);

            $rply = $this->get_lines();
            $code = substr($rply,0,3);

            if($this->do_debug >= 2) {
                echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
            }

            if($code != 250 && $code != 251) {
                $this->error =
                    array("error" => "RCPT not accepted from server",
                          "smtp_code" => $code,
                          "smtp_msg" => substr($rply,4));
                if($this->do_debug >= 1) {
                    echo "SMTP -> ERROR: " . $this->error["error"] .
                             ": " . $rply . $this->CRLF;
                }
                return false;
            }
            return true;
        }

        /*
         * Reset()
         *
         * Sends the RSET command to abort and transaction that is
         * currently in progress. Returns true if successful false
         * otherwise.
         *
         * Implements rfc 821: RSET <CRLF>
         *
         * SMTP CODE SUCCESS: 250
         * SMTP CODE ERROR  : 500,501,504,421
         */
        function Reset() {
            $this->error = null; # so no confusion is caused

            if(!$this->connected()) {
                $this->error = array(
                        "error" => "Called Reset() without being connected");
                return false;
            }

            fputs($this->smtp_conn,"RSET" . $this->CRLF);

            $rply = $this->get_lines();
            $code = substr($rply,0,3);

            if($this->do_debug >= 2) {
                echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
            }

            if($code != 250) {
                $this->error =
                    array("error" => "RSET failed",
                          "smtp_code" => $code,
                          "smtp_msg" => substr($rply,4));
                if($this->do_debug >= 1) {
                    echo "SMTP -> ERROR: " . $this->error["error"] .
                             ": " . $rply . $this->CRLF;
                }
                return false;
            }

            return true;
        }

        /*
         * Send($from)
         *
         * 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.
         *
         * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
         *
         * SMTP CODE SUCCESS: 250
         * SMTP CODE SUCCESS: 552,451,452
         * SMTP CODE SUCCESS: 500,501,502,421
         */
        function Send($from) {
            $this->error = null; # so no confusion is caused

            if(!$this->connected()) {
                $this->error = array(
                        "error" => "Called Send() without being connected");
                return false;
            }

            fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);

            $rply = $this->get_lines();
            $code = substr($rply,0,3);

            if($this->do_debug >= 2) {
                echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
            }

            if($code != 250) {
                $this->error =
                    array("error" => "SEND not accepted from server",
                          "smtp_code" => $code,
                          "smtp_msg" => substr($rply,4));
                if($this->do_debug >= 1) {
                    echo "SMTP -> ERROR: " . $this->error["error"] .
                             ": " . $rply . $this->CRLF;
                }
                return false;
            }
            return true;
        }

        /*
         * SendAndMail($from)
         *
         * 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
         */
        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) {
                echo "SMTP -> FROM SERVER:" . $this->CRLF . $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) {
                    echo "SMTP -> ERROR: " . $this->error["error"] .
                             ": " . $rply . $this->CRLF;
                }
                return false;
            }
            return true;
        }

        /*
         * SendOrMail($from)
         *
         * 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 or mail it to them if they are not.
         *
         * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
         *
         * SMTP CODE SUCCESS: 250
         * SMTP CODE SUCCESS: 552,451,452
         * SMTP CODE SUCCESS: 500,501,502,421
         */
        function SendOrMail($from) {
            $this->error = null; # so no confusion is caused

            if(!$this->connected()) {
                $this->error = array(
                    "error" => "Called SendOrMail() without being connected");
                return false;
            }

            fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);

            $rply = $this->get_lines();
            $code = substr($rply,0,3);

            if($this->do_debug >= 2) {
                echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
            }

            if($code != 250) {
                $this->error =
                    array("error" => "SOML not accepted from server",
                          "smtp_code" => $code,
                          "smtp_msg" => substr($rply,4));
                if($this->do_debug >= 1) {
                    echo "SMTP -> ERROR: " . $this->error["error"] .
                             ": " . $rply . $this->CRLF;
                }
                return false;
            }
            return true;
        }

        /*
         * Turn()
         *
         * This is an optional command for SMTP that this class does not
         * support. This method is here to make the RFC821 Definition
         * complete for this class and __may__ be implimented in the future
         *
         * Implements from rfc 821: TURN <CRLF>
         *
         * SMTP CODE SUCCESS: 250
         * SMTP CODE FAILURE: 502
         * SMTP CODE ERROR  : 500, 503
         */
        function Turn() {
            $this->error = array("error" => "This method, TURN, of the SMTP ".
                                            "is not implemented");
            if($this->do_debug >= 1) {
                echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
            }
            return false;
        }

        /*
         * Verify($name)
         *
         * Verifies that the name is recognized by the server.
         * Returns false if the name could not be verified otherwise
         * the response from the server is returned.
         *
         * Implements rfc 821: VRFY <SP> <string> <CRLF>
         *
         * SMTP CODE SUCCESS: 250,251
         * SMTP CODE FAILURE: 550,551,553
         * SMTP CODE ERROR  : 500,501,502,421
         */
        function Verify($name) {
            $this->error = null; # so no confusion is caused

            if(!$this->connected()) {
                $this->error = array(
                        "error" => "Called Verify() without being connected");
                return false;
            }

            fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);

            $rply = $this->get_lines();
            $code = substr($rply,0,3);

            if($this->do_debug >= 2) {
                echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
            }

            if($code != 250 && $code != 251) {
                $this->error =
                    array("error" => "VRFY failed on name '$name'",
                          "smtp_code" => $code,
                          "smtp_msg" => substr($rply,4));
                if($this->do_debug >= 1) {
                    echo "SMTP -> ERROR: " . $this->error["error"] .
                             ": " . $rply . $this->CRLF;
                }
                return false;
            }
            return $rply;
        }

        /******************************************************************
         *                       INTERNAL FUNCTIONS                       *
         ******************************************************************/

        /*
         * get_lines()
         *
         * __internal_use_only__: read in as many lines as possible
         * either before eof or socket timeout occurs on the operation.
         * With SMTP we can tell if we have more lines to read if the
         * 4th character is '-' symbol. If it is a space then we don't
         * need to read anything else.
         */
        function get_lines() {
            $data = "";
            while($str = fgets($this->smtp_conn,515)) {
                if($this->do_debug >= 4) {
                    echo "SMTP -> get_lines(): \$data was \"$data\"" .
                             $this->CRLF;
                    echo "SMTP -> get_lines(): \$str is \"$str\"" .
                             $this->CRLF;
                }
                $data .= $str;
                if($this->do_debug >= 4) {
                    echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
                }
                # if the 4th character is a space then we are done reading
                # so just break the loop
                if(substr($str,3,1) == " ") { break; }
            }
            return $data;
        }

    }


 ?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -