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->發送">

首頁  >  文章  >  後端開發  >  she is my sin gtp smtp郵件發送一例

she is my sin gtp smtp郵件發送一例

WBOY
WBOY原創
2016-07-29 08:34:431155瀏覽

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);
}

{
  if(GetType($responses)!="array")
   $resp>  Unset($match_code);
  while(($line=$this->Get);
  while(($line=$this->Get);
  while(($line=$this->Getconection($this-connection )))
  {
   if(IsSet($match_code) ))
   {
    if(strcmp >     $this->error=$line;
     return(0 $line," -");
    if(GetType($code)=="array")
    {
     for($codes=0;$codes     if($codes>=count ($code))
     {
      }
    }
    其他
    {
     if(strcmp($match_code,$code))
     return(0);
}
    }
   }
   $responses[]=strtok("");
   if(!strcmp($match_code,strtok(> ;
  }
  return(-1);
}
函數FlushRecipients()
{
  if($ this->VerifyResultLines("250")    return(0);
   $this->pending_sender=0;
  }pending_recipients--)
  {
   if($this->VerifyResultLines(array("250","251"))  >  return(1);
}
/* 公共方法*/
Function Connect()
{
  $this->error=$ error="";
  ->esmtp_host="";
   $this->esmtp_extensi>  if(!($this->c ? fsockopen($this->host_name,$this ->host_port,&$errno,&$error,$this ->timeout) : fsockopen($this->host_name,$this->host_port))))
  {
   switch($錯誤)
    🠎>this switch($錯誤)
    ->error=" 能夠創建-3 SDK";
     return(0);
    case -4:
     $this->error="-4 主機名稱"".上_name.$的dns 尋找失敗";
     return(0);
    case -5:
     $ >    case -6:
     $this->error="-6 fdopen() 呼叫失敗";
     return (0);     return(0);
    預設值:
     $this- >error=$error." 無法連線至主機數"name.$ ";
     return(0);
   }
  }
  else
  {
thisofm-host&Pm

   && !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 ); if($success)
    $success= $disconnect_success;
  }
  return($success);
}
};
?>

以上就介紹了she is my sin gtp smtp郵件發送一例,包括she is my sin gtp方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn