host_name="mail.xiaocui.com "; $smtp->localhost="localhost";$from="webmaster@xiaocui.com";$to="root@xiaocui.com";if($smtp->發送"/> host_name="mail.xiaocui.com "; $smtp->localhost="localhost";$from="webmaster@xiaocui.com";$to="root@xiaocui.com";if($smtp->發送">
test_smtp.php
require("smtp.php");
$smtp=new smtp_class;
$smtp->host_name="mail.xiaocui.com";
$$smtp->host_name="mail.xiaocui.com";
$$ smtp->localhost="localhost";
$from="webmaster@xiaocui.com";
$to="root@xiaocui.com";
if($smtp->; SendMessage(
$from,
array(
$to
),
array(
🎜 > 「主題:測試Manuel Lemos 的SMTP 類別」
),
「Hello $to,nn這只是為了讓您知道您的SMTP 類別運作良好。nnBye.n」))
echo "訊息已寄至$to OK.n";
else
echo "無法將訊息傳送至$to.nError: ".$smtp->error."n"
?>
smtp.php
class smtp_class
{
var $host_name="";
var $host_port=25;
var $localhost="";
var $timeout=0;
var $error="";
var $debug=1;
var $esmtp=1;
var $esmtp_host="";
var $esmtp_extensi >var $maximum_piped_recipients=100;
/* 私有變數- 請勿存取*/
var $state="Disconnected";
var $c>var $pending_recipients=0;
/ * 私有方法- 請勿呼叫*/
Function OutputDebug($message)
{
echo $message,"
n";
}
Function GetLine()
{
{
{ 🎜> for($line="";;)
{
if(feof($this->connection))
{ return(0);
}
if(($data=fgets($this->connection,100))==false)
{
{
$this->error="無法從套接字讀取行";
return(0);
}
$line.=$$mmmo> );
if($length>=2
&& substr($line,$length-2,2)=="rn")
{
,$length-2);
if($this->debug)
$this->OutputDebug(" return($eturn($line); > }
}
函數PutLine($line)
{
if($this->debug )
$this->OutputDebug("> $line")
$this->OutputDebug("> $line"); $this->OutputDebug("> $line"); (!fputs($this->connection,"$linern"))
{
$this- >error="無法將行寫入套接字";
return(0);
}
return(1);
}
函數PutData($data)
{
if(strlen($data))
this {debug)
$this->OutputDebug("> $data");
if(!fputs($this->connection,$data))
{
"無法將資料寫入套接字";
return(0) ;
}
}
return(1);
}
&& !strcmp( $localhost=getenv("HOST"),""))
$success=0;
if($this->VerifyResultLines("220")> p> if( $this->PutLine("EHLO $localhost")
&& $this->VerifyResultLines("250",&$responses)>0)
{
$this->esmtp_host=strtok( $responses [0]," ");
for($resp> {
$extension=strtoupper(strtok($res ension ]=strtok("");
}
$success=1;
}
->PutLine("HELO $localhost ")
&& $this->VerifyResultLines(" 250")>0)
$success=1; state="已連接";
return( 1);
}
else
{
fclose($this->connection);
$this->c> }
}
}
函數MailFrom($sender)
{
if(strcmp($this->state,"已連結")) ->error="連線未處於初始狀態";
return(0);
}
$this->error="";
if(!$ this->PutLine("郵件寄件者:"))
return(0);
if(!IsSet($this->esmtp_extensions["PIPELINING"] )
&& $this-> VerifyResultLines("250") return(0);
$this->state="SenderSet";
if(IsSet( $this->esmtp_extensions[🎜> if(IsSet( $this->esmtp_extensions["PIPEING"])
$this->pending_sender=1;
$this->pending_recipients=0;
return(1);
}
函數SetRecipipf> switch($this->state)
{
case "SenderSet":
case "RecipientSet":
處於接收者設定狀態";
return(0);
}
$this->error="";
if(!$this->PutLine("RCPT TO:"))
return(0);
if(IsSet($this->") esmtp_extensions["PIPELINING"]))
{ if($this->pending_recipients>=$this->maximum_piped_recipients)
{
if }
}
else
{
if($this->VerifyResultLines(array(") 250","251")) > 🎜> $this->state="RecipientSet";
return(1);
}
函數StartData()
{
if(strcmp($this->state,"RecipientSet "))
{
$this->error="連線不在開始傳送資料狀態";
return(0);
}
$-0);
}
$-> 🎜> if(!$this->PutLine("DATA"))
return(0);
if($this->pending_recipients)
this { ())
return(0);
}
if($this->VerifyResultLines("354") return(0);
="SendingData";
return(1 );
}
函數PrepareData($data,&$output)
{
$length=strlen(&$data); for($output="",$position= 0;$position {
$next_position=$length;
for($current=$position=$length;
for($current=$position=$length;
th for($current=$position;$current {
switch ($data[$current])
{
break 2;
case "r":
case "r":
$next_position =$current+1;
if($data[ break 2;
}
}
if($data [$position]==".")
$output.=".";
$output.=substr(&$currentdata,$position,$current -$position)."rn";
$position=$next_position;
}
}
函數SendData($data)
{
this
thiso> state,"SendingData"))
{
$this->error="連接未處於發送數據狀態";
return(0);
}
$this->error= "";
return($this->PutData(&$data));
}
Function EndSendingData()
{
if(strcmp($this->state,"SendingData"))
{
$this->error="連線不在正在傳送資料狀態" ;
return(0);
}
$this->error="";
if(!$this->PutLine("rn.")
if(!$this->PutLine("rn.")
if(!$this->PutLine("rn.")
if >VerifyResultLines("250") return(0);
$this->state="已連接";
return(1);
}
}
函數ResetConnectionConnection ()
{
switch($this->state)
{
case "Connected":
return(1);thiserror="傳送資料時無法重設連線";
return(0);
case "Disconnected":
$this->error ="在建立連線之前無法重設連線連線」;
return(0);
}
$this->error="";
if(!$this->PutLine ("RSET") return(0);
$this->state="已連接";
return(1);
}
函數斷開連接($quit=1)
{
if(!strcmp($this->state,"Disconnected"))
{
$this->error="之前未建立SMTP 連線";
return(0);
}
$this->error="";
if( !strcmp($this->state,"已連接")
if( !strcmp($this->state,"已連接")
& $quit
&& (!$this->PutLine("QUIT")
|| $this->VerifyResultLines("221") return(0)
;
return(0)
;
; ->connection);
$this->c> $this ->state="Disconnected";
return(1);
}
函數SendMessage($sender,$recipients,$headers ,$body)
{
if(($ success=$this->Connect()))
{
if(($success=$this->MailFrom($sender)))
{
for($recipient=0 ;$recipient
.$58885( recipients])))
break;
}
if($success
for($header_data= "",$header=0;$header $header_data.=$headers[$header]."rn";
>SendData($header_data."rn") ))
{
$this->PrepareData($body,&$body_data);
this 🎜> }
if( $success)
$success=$this->EndSendingData );
$success= $disconnect_success;
}
return($success);
}
};
?>
以上就介紹了she is my sin gtp smtp郵件發送一例,包括she is my sin gtp方面的內容,希望對PHP教程有興趣的朋友有所幫助。