亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

smtp郵件發送一例

2019-11-18 21:52:18
字體:
來源:轉載
供稿:網友
test_smtp.php

<?
require("smtp.php");

$smtp=new smtp_class;

$smtp->host_name="mail.xiaocui.com";
$smtp->localhost="localhost";
$from="webmaster@xiaocui.com";
$to="root@xiaocui.com";
if($smtp->SendMessage(
  $from,
  array(
   $to
  ),
  array(
   "From: $from",
   "To: $to",
   "Subject: Testing Manuel Lemos' SMTP class"
  ),
  "Hello $to,/n/nIt is just to let you know that your SMTP class is working just fine./n/nBye./n"))
  echo "Message sent to $to OK./n";
else
  echo "Cound not send the message to $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_extensions=array();
var $maximum_piped_recipients=100;

/* PRivate variables - DO NOT access */

var $state="Disconnected";
var $connection=0;
var $pending_recipients=0;

/* Private methods - DO NOT CALL */

Function OutputDebug($message)
{
  echo $message,"<br>/n";
}

Function GetLine()
{
  for($line="";;)
  {
   if(feof($this->connection))
   {
    $this->error="reached the end of stream while reading from socket";
    return(0);
   }
   if(($data=fgets($this->connection,100))==false)
   {
    $this->error="it was not possible to read line from socket";
    return(0);
   }
   $line.=$data;
   $length=strlen($line);
   if($length>=2
   && substr($line,$length-2,2)=="/r/n")
   {
    $line=substr($line,0,$length-2);
    if($this->debug)
     $this->OutputDebug("< $line");
    return($line);
   }
  }
}

Function PutLine($line)
{
  if($this->debug)
   $this->OutputDebug("> $line");
  if(!fputs($this->connection,"$line/r/n"))
  {
   $this->error="it was not possible to write line to socket";
   return(0);
  }
  return(1);
}

Function PutData($data)
{
  if(strlen($data))
  {
   if($this->debug)
    $this->OutputDebug("> $data");
   if(!fputs($this->connection,$data))
   {
    $this->error="it was not possible to write data to socket";
    return(0);
   }
  }
  return(1);
}

Function VerifyResultLines($code,$responses="")
{
  if(GetType($responses)!="array")
   $responses=array();
  Unset($match_code);

  while(($line=$this->GetLine($this->connection)))
  {
   if(IsSet($match_code))
   {
    if(strcmp(strtok($line," -"),$match_code))
    {
     $this->error=$line;
     return(0);
    }
   }
   else
   {
    $match_code=strtok($line," -");
    if(GetType($code)=="array")
    {
     for($codes=0;$codes<count($code) && strcmp($match_code,$code[$codes]);$codes++);
     if($codes>=count($code))
     {
      $this->error=$line;
      return(0);
     }
    }
    else
    {
     if(strcmp($match_code,$code))
     {
      $this->error=$line;
      return(0);
     }
    }
   }
   $responses[]=strtok("");
   if(!strcmp($match_code,strtok($line," ")))
    return(1);
  }
  return(-1);
}

Function FlushRecipients()
{
  if($this->pending_sender)
  {
   if($this->VerifyResultLines("250")<=0)
    return(0);
   $this->pending_sender=0;
  }
  for(;$this->pending_recipients;$this->pending_recipients--)
  {
   if($this->VerifyResultLines(array("250","251"))<=0)
    return(0);
  }
  return(1);
}

/* Public methods */

Function Connect()
{
  $this->error=$error="";
   $this->esmtp_host="";
   $this->esmtp_extensions=array();
  if(!($this->connection=($this->timeout ? fsockopen($this->host_name,$this->host_port,&$errno,&$error,$this->timeout) : fsockopen($this->host_name,$this->host_port))))
  {
   switch($error)
   {
    case -3:
     $this->error="-3 socket could not be created";
     return(0);
    case -4:
     $this->error="-4 dns lookup on hostname /"".$host_name."/" failed";
     return(0);
    case -5:
     $this->error="-5 connection refused or timed out";
     return(0);
    case -6:
     $this->error="-6 fdopen() call failed";
     return(0);
    case -7:
     $this->error="-7 setvbuf() call failed";
     return(0);
    default:
     $this->error=$error." could not connect to the host /"".$this->host_name."/"";
     return(0);
   }
  }
  else
  {
   if(!strcmp($localhost=$this->localhost,"")
   && !strcmp($localhost=getenv("SERVER_NAME"),"")
   && !strcmp($localhost=getenv("HOST"),""))
     $localhost="localhost";
    $success=0;
    if($this->VerifyResultLines("220")>0)
    {
     if($this->esmtp)
     {
      $responses=array();
      if($this->PutLine("EHLO $localhost")
      && $this->VerifyResultLines("250",&$responses)>0)
      {
       $this->esmtp_host=strtok($responses[0]," ");
       for($response=1;$response<count($responses);$response++)
       {
        $extension=strtoupper(strtok($responses[$response]," "));
        $this->esmtp_extensions[$extension]=strtok("");
       }
       $success=1;
      }
     }
     if(!$success
     && $this->PutLine("HELO $localhost")
     && $this->VerifyResultLines("250")>0)
      $success=1;
   }
   if($success)
   {
    $this->state="Connected";
    return(1);
   }
   else
   {
    fclose($this->connection);
    $this->connection=0;
    $this->state="Disconnected";
    return(0);
   }
  }
}

Function MailFrom($sender)
{
  if(strcmp($this->state,"Connected"))
  {
   $this->error="connection is not in the initial state";
   return(0);
  }
  $this->error="";
  if(!$this->PutLine("MAIL FROM: &lt;".$sender."&gt;"))
   return(0);
  if(!IsSet($this->esmtp_extensions["PIPELINING"])
  && $this->VerifyResultLines("250")<=0)
   return(0);
  $this->state="SenderSet";
  if(IsSet($this->esmtp_extensions["PIPELINING"]))
   $this->pending_sender=1;
  $this->pending_recipients=0;
  return(1);
}

Function SetRecipient($recipient)
{
  switch($this->state)
  {
   case "SenderSet":
   case "RecipientSet":
    break;
   default:
    $this->error="connection is not in the recipient setting state";
    return(0);
  }
  $this->error="";
  if(!$this->PutLine("RCPT TO:&lt;".$recipient."&gt;"))
   return(0);
  if(IsSet($this->esmtp_extensions["PIPELINING"]))
  {
   $this->pending_recipients++;
   if($this->pending_recipients>=$this->maximum_piped_recipients)
   {
    if(!$this->FlushRecipients())
     return(0);
   }
  }
  else
  {
   if($this->VerifyResultLines(array("250","251"))<=0)
    return(0);
  }
  $this->state="RecipientSet";
  return(1);
}

Function StartData()
{
  if(strcmp($this->state,"RecipientSet"))
  {
   $this->error="connection is not in the start sending data state";
   return(0);
  }
  $this->error="";
  if(!$this->PutLine("DATA"))
   return(0);
  if($this->pending_recipients)
  {
   if(!$this->FlushRecipients())
    return(0);
  }
  if($this->VerifyResultLines("354")<=0)
   return(0);
  $this->state="SendingData";
  return(1);
}

Function PrepareData($data,&$output)
{
  $length=strlen(&$data);
  for($output="",$position=0;$position<$length;)
  {
   $next_position=$length;
   for($current=$position;$current<$length;$current++)
   {
    switch($data[$current])
    {
     case "/n":
      $next_position=$current+1;
      break 2;
     case "/r":
      $next_position=$current+1;
      if($data[$next_position]=="/n")
       $next_position++;
      break 2;
    }
   }
   if($data[$position]==".")
    $output.=".";
   $output.=substr(&$data,$position,$current-$position)."/r/n";
   $position=$next_position;
  }
}

Function SendData($data)
{
  if(strcmp($this->state,"SendingData"))
  {
   $this->error="connection is not in the sending data state";
   return(0);
  }
  $this->error="";
  return($this->PutData(&$data));
}

Function EndSendingData()
{
  if(strcmp($this->state,"SendingData"))
  {
   $this->error="connection is not in the sending data state";
   return(0);
  }
  $this->error="";
  if(!$this->PutLine("/r/n.")
  || $this->VerifyResultLines("250")<=0)
   return(0);
  $this->state="Connected";
  return(1);
}

Function ResetConnection()
{
  switch($this->state)
  {
   case "Connected":
    return(1);
   case "SendingData":
    $this->error="can not reset the connection while sending data";
    return(0);
   case "Disconnected":
    $this->error="can not reset the connection before it is established";
    return(0);
  }
  $this->error="";
  if(!$this->PutLine("RSET")
  || $this->VerifyResultLines("250")<=0)
   return(0);
  $this->state="Connected";
  return(1);
}

Function Disconnect($quit=1)
{
  if(!strcmp($this->state,"Disconnected"))
  {
   $this->error="it was not previously established a SMTP connection";
   return(0);
  }
  $this->error="";
  if(!strcmp($this->state,"Connected")
  && $quit
  && (!$this->PutLine("QUIT")
  || $this->VerifyResultLines("221")<=0))
   return(0);
  fclose($this->connection);
  $this->connection=0;
  $this->state="Disconnected";
  return(1);
}

Function SendMessage($sender,$recipients,$headers,$body)
{
  if(($success=$this->Connect()))
  {
   if(($success=$this->MailFrom($sender)))
   {
    for($recipient=0;$recipient<count($recipients);$recipient++)
    {
     if(!($success=$this->SetRecipient($recipients[$recipient])))
      break;
    }
    if($success
    && ($success=$this->StartData()))
    {
     for($header_data="",$header=0;$header<count($headers);$header++)
      $header_data.=$headers[$header]."/r/n";
     if(($success=$this->SendData($header_data."/r/n")))
     {
      $this->PrepareData($body,&$body_data);
      $success=$this->SendData($body_data);
     }
     if($success)
      $success=$this->EndSendingData();
    }
   }
   $disconnect_success=$this->Disconnect($success);
   if($success)
    $success=$disconnect_success;
  }
  return($success);
}

};

?>



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
中文字幕一区电影| 一本一本久久a久久精品综合小说| 亚洲精品久久视频| 97在线精品国自产拍中文| 欧美午夜精品久久久久久人妖| 欧美日韩性视频在线| 欧美激情一区二区三区高清视频| 午夜精品一区二区三区在线视频| 欧美成人免费全部观看天天性色| 亚洲国产小视频| 色偷偷噜噜噜亚洲男人的天堂| 久久久久久av| 狠狠色香婷婷久久亚洲精品| 久久乐国产精品| 日韩av在线网站| 色婷婷**av毛片一区| 热门国产精品亚洲第一区在线| 97**国产露脸精品国产| 亚洲第一区在线观看| 少妇高潮 亚洲精品| 成人欧美一区二区三区在线| 欧美日韩ab片| 久久久伊人日本| 日韩人体视频一二区| 日本久久久久亚洲中字幕| 日韩资源在线观看| 欧美激情小视频| 丰满岳妇乱一区二区三区| 福利一区福利二区微拍刺激| 高清欧美一区二区三区| 亚洲精品suv精品一区二区| 亚洲精品国产成人| 亚洲欧美精品一区二区| 欧美日本中文字幕| 日韩一区二区三区xxxx| 亚洲精品在线不卡| 亚洲片在线资源| 欧美性少妇18aaaa视频| 国产精品视频在线观看| 国产精品入口福利| 久久久久www| www亚洲欧美| 97精品免费视频| 国产亚洲欧美aaaa| 国产亚洲欧美日韩一区二区| 欧美日产国产成人免费图片| 91亚洲永久免费精品| 在线成人一区二区| 日韩欧美在线播放| 91影视免费在线观看| 日韩av一卡二卡| 欧美大码xxxx| 久久夜精品va视频免费观看| 97超级碰碰碰| 亚洲第一福利网站| 欧美中文字幕视频在线观看| 欧美视频在线看| 欧美高清理论片| 日韩免费视频在线观看| 性欧美在线看片a免费观看| 色婷婷综合久久久久中文字幕1| 欧美激情中文网| 夜夜嗨av一区二区三区四区| 国产精品99久久久久久人| 欧美大片大片在线播放| 亚洲国产精品久久久久久| 国产精品视频白浆免费视频| 国产亚洲欧美aaaa| 亚洲精品二三区| 最近2019免费中文字幕视频三| 亚洲а∨天堂久久精品9966| 国产91精品高潮白浆喷水| 成人h视频在线观看播放| 成人欧美一区二区三区黑人| 美日韩丰满少妇在线观看| 日本精品视频在线观看| 亚洲天堂网站在线观看视频| 最近2019中文字幕mv免费看| 九九热这里只有在线精品视| 欧美亚洲国产精品| 亚洲精品影视在线观看| 国产精品免费久久久久久| 国产精品久久久久久久久男| 91精品国产乱码久久久久久久久| 欧美日韩美女视频| 国产精品美女久久久久av超清| 97超级碰碰碰久久久| 日本免费一区二区三区视频观看| 欧美xxxx14xxxxx性爽| 国产91成人在在线播放| 亚洲欧美制服丝袜| 欧美一级片一区| 欧美在线性视频| www亚洲欧美| 午夜精品一区二区三区在线视频| 色综合伊人色综合网站| 久久免费视频观看| 国产精品r级在线| 国产日韩在线精品av| 性欧美视频videos6一9| 国产精品91久久| 亚洲电影av在线| 久久久久久久久久av| 精品无人国产偷自产在线| 色中色综合影院手机版在线观看| 国产精品羞羞答答| 色七七影院综合| 日本精品一区二区三区在线播放视频| www.久久撸.com| 91国偷自产一区二区三区的观看方式| 日韩欧美一区二区三区久久| 亚洲色图校园春色| 成人福利免费观看| 成人福利视频在线观看| 最近中文字幕mv在线一区二区三区四区| 欧美日韩美女在线| 91中文字幕一区| 欧美高清电影在线看| 欧美性videos高清精品| 日韩精品极品毛片系列视频| 国产精品白丝jk喷水视频一区| 欧美—级a级欧美特级ar全黄| 久久久久久久久久亚洲| 亚洲欧美精品suv| 国产精品白丝jk喷水视频一区| 亚洲国产一区二区三区在线观看| 久久久综合av| 欧美日韩国产在线看| 亚洲国产99精品国自产| 成人亲热视频网站| 欧美洲成人男女午夜视频| 91av中文字幕| 亚洲乱码一区av黑人高潮| 日本不卡视频在线播放| 亚洲国产精品va在线观看黑人| 国产精品视频导航| 91精品久久久久久久久不口人| 亚洲国产精品人久久电影| 国产精品99蜜臀久久不卡二区| 色妞色视频一区二区三区四区| 国产成人激情小视频| 国产视频亚洲精品| 中日韩美女免费视频网站在线观看| 亚洲成年人影院在线| 欧美自拍大量在线观看| 日韩有码片在线观看| 国产精品黄页免费高清在线观看| 精品视频在线观看日韩| 欧美性猛交丰臀xxxxx网站| 亚洲自拍偷拍色图| 97香蕉久久夜色精品国产| 亚洲精品wwwww| 日韩在线观看你懂的| 亚洲天堂久久av| 国产成人精品视频在线观看| 国产精品久久久久久久久久ktv| 日韩美女中文字幕| 午夜精品一区二区三区在线视频| 亚洲四色影视在线观看| 欧美精品在线极品| 一区二区欧美在线| 中文字幕日本欧美| 国产精品久久久久久久久久久久| 亚洲国产精品va在线看黑人|