📄 class.smtp.php
字号:
$this->error = array(
"error" => "HELP not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr( $rply, 4 )
);
if ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return $rply;
}
public function Mail( $from )
{
$this->error = null;
if ( !$this->connected( ) )
{
$this->error = array( "error" => "Called Mail() without being connected" );
return false;
}
fputs( $this->smtp_conn, "MAIL FROM:<".$from.">".$this->CRLF );
$rply = $this->get_lines( );
$code = substr( $rply, 0, 3 );
if ( 2 <= $this->do_debug )
{
echo "SMTP -> FROM SERVER:".$this->CRLF.$rply;
}
if ( $code != 250 )
{
$this->error = array(
"error" => "MAIL not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr( $rply, 4 )
);
if ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return true;
}
public function Noop( )
{
$this->error = null;
if ( !$this->connected( ) )
{
$this->error = array( "error" => "Called Noop() without being connected" );
return false;
}
fputs( $this->smtp_conn, "NOOP".$this->CRLF );
$rply = $this->get_lines( );
$code = substr( $rply, 0, 3 );
if ( 2 <= $this->do_debug )
{
echo "SMTP -> FROM SERVER:".$this->CRLF.$rply;
}
if ( $code != 250 )
{
$this->error = array(
"error" => "NOOP not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr( $rply, 4 )
);
if ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return true;
}
public function Quit( $close_on_error = true )
{
$this->error = null;
if ( !$this->connected( ) )
{
$this->error = array( "error" => "Called Quit() without being connected" );
return false;
}
fputs( $this->smtp_conn, "quit".$this->CRLF );
$byemsg = $this->get_lines( );
if ( 2 <= $this->do_debug )
{
echo "SMTP -> FROM SERVER:".$this->CRLF.$byemsg;
}
$rval = true;
$e = null;
$code = substr( $byemsg, 0, 3 );
if ( $code != 221 )
{
$e = array(
"error" => "SMTP server rejected quit command",
"smtp_code" => $code,
"smtp_rply" => substr( $byemsg, 4 )
);
$rval = false;
if ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$e['error'].": ".$byemsg.$this->CRLF;
}
}
if ( empty( $e ) || $close_on_error )
{
$this->Close( );
}
return $rval;
}
public function Recipient( $to )
{
$this->error = null;
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 ( 2 <= $this->do_debug )
{
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 ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return true;
}
public function Reset( )
{
$this->error = null;
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 ( 2 <= $this->do_debug )
{
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 ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return true;
}
public function Send( $from )
{
$this->error = null;
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 ( 2 <= $this->do_debug )
{
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 ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return true;
}
public function SendAndMail( $from )
{
$this->error = null;
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 ( 2 <= $this->do_debug )
{
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 ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return true;
}
public function SendOrMail( $from )
{
$this->error = null;
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 ( 2 <= $this->do_debug )
{
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 ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return true;
}
public function Turn( )
{
$this->error = array( "error" => "This method, TURN, of the SMTP is not implemented" );
if ( 1 <= $this->do_debug )
{
echo "SMTP -> NOTICE: ".$this->error['error'].$this->CRLF;
}
return false;
}
public function Verify( $name )
{
$this->error = null;
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 ( 2 <= $this->do_debug )
{
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 ( 1 <= $this->do_debug )
{
echo "SMTP -> ERROR: ".$this->error['error'].": ".$rply.$this->CRLF;
}
return false;
}
return $rply;
}
public function get_lines( )
{
$data = "";
while ( $str = fgets( $this->smtp_conn, 515 ) )
{
if ( 4 <= $this->do_debug )
{
echo "SMTP -> get_lines(): \$data was \"".$data."\"".$this->CRLF;
echo "SMTP -> get_lines(): \$str is \"".$str."\"".$this->CRLF;
}
$data .= $str;
if ( 4 <= $this->do_debug )
{
echo "SMTP -> get_lines(): \$data is \"".$data."\"".$this->CRLF;
}
if ( !( substr( $str, 3, 1 ) == " " ) )
{
continue;
}
break;
}
return $data;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -