public function StartTLS()
    {
        $this->error = null; # to avoid confusion

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

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

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

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

        if ($code != 220) {
            $this->error =
            array("error" => "STARTTLS 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 . '<br />';
            }
            return false;
        }

        // Begin encrypted connection
        if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
            return false;
        }

        return true;
    }
public function StartTLS()
    {
        $this->error = null; # to avoid confusion

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

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

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

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

        if ($code != 220) {
            $this->error =
            array("error" => "STARTTLS 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 . '<br />';
            }
            return false;
        }

        // Begin encrypted connection
        if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
            return false;
        }

        return true;
    }
public function StartTLS ( ) { $ this -> error = null ; # to avoid confusion if ( ! $ this -> connected ( ) ) { $ this -> error = array ( "error" => "Called StartTLS() without being connected" ) ; return false ; } fputs ( $ this -> smtp_conn , "STARTTLS" . $ this -> CRLF ) ; $ rply = $ this -> get_lines ( ) ; $ code = substr ( $ rply , 0 , 3 ) ; if ( $ this -> do_debug >= 2 ) { echo "SMTP -> FROM SERVER:" . $ rply . $ this -> CRLF . '<br />' ; } if ( $ code != 220 ) { $ this -> error = array ( "error" => "STARTTLS 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 . '<br />' ; } return false ; } // Begin encrypted connection if ( ! stream_socket_enable_crypto ( $ this -> smtp_conn , true , STREAM_CRYPTO_METHOD_TLS_CLIENT ) ) { return false ; } return true ; }
Initiate a TLS communication with the server.

SMTP CODE 220 Ready to start TLS
SMTP CODE 501 Syntax error (no parameters allowed)
SMTP CODE 454 TLS not available due to temporary reason
@access public
@return bool success
Initiate a TLS communication with the server .