中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

php Socket發(fā)送郵件驗(yàn)證郵箱的真實(shí)有效性而非格式

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
<?php

/*請(qǐng)尊重別人的勞動(dòng)成功,請(qǐng)保留此版權(quán)信息,謝謝!
作者:小露珠3.3
揚(yáng)帆修正一點(diǎn)東西:在代碼中已經(jīng)用注釋注明,本代碼現(xiàn)在向qq發(fā)信沒問題~
*/
set_time_limit(120);

class smtp_mail
{
    var $host;           //主機(jī)
    var $port;           //端口 一般為25
    var $user;           //SMTP認(rèn)證的帳號(hào)
    var $pass;           //認(rèn)證密碼
    var $debug = false;   //是否顯示和服務(wù)器會(huì)話信息?
    var $conn;
    var $result_str;       //結(jié)果
    var $in;           //客戶機(jī)發(fā)送的命令
    var $from;           //源信箱
    var $to;           //目標(biāo)信箱
    var $subject;         //主題
    var $body;           //內(nèi)容
    function smtp_mail($host,$port,$user,$pass,$debug=false)
    {
       $this->host   = $host;
       $this->port   = $port;
       $this->user   = base64_encode($user);
       $this->pass   = base64_encode($pass);
       $this->debug   = $debug;
       $this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);   //具體用法請(qǐng)參考手冊(cè)
       if($this->socket)
       {
       $this->result_str   =   "創(chuàng)建SOCKET:".socket_strerror(socket_last_error());
       $this->debug_show($this->result_str);
       }
       else
       {
       exit("初始化失敗,請(qǐng)檢查您的網(wǎng)絡(luò)連接和參數(shù)");
       }
       $this->conn = socket_connect($this->socket,$this->host,$this->port);
       if($this->conn)
       {
       $this->result_str   =   "創(chuàng)建SOCKET連接:".socket_strerror(socket_last_error());
       $this->debug_show($this->result_str);
       }
       else
       {
       exit("初始化失敗,請(qǐng)檢查您的網(wǎng)絡(luò)連接和參數(shù)");
       }
       $this->result_str = "服務(wù)器應(yīng)答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
       $this->debug_show($this->result_str);

    }
    function debug_show($str)
    {
       if($this->debug)
       {
       echo $str."<p>\r\n";
       }
    }
    function send($from,$to,$subject,$body)
    {
       if($from == "" || $to == "")
       {
       exit("請(qǐng)輸入信箱地址");
       }
       if($subject == "") $sebject = "無標(biāo)題";
       if($body     == "") $body     = "無內(nèi)容";
       $this->from     =   $from;
       $this->to       =   $to;
       $this->subject   =   $subject;
       $this->body     =   $body;

           //揚(yáng)帆修改部分代碼
       $All           = "From:<".$this->from.">\r\n";
       $All           .= "To:<".$this->to.">\r\n";
       $All           .= "Subject:".$this->subject."\r\n\r\n";
       $All           .= $this->body;
       /*
       如過把$All的內(nèi)容再加處理,就可以實(shí)現(xiàn)發(fā)送MIME郵件了
       不過還需要加很多程序
       */

       //以下是和服務(wù)器會(huì)話
       $this->in       =   "EHLO HELO\r\n";
       $this->docommand();

       $this->in       =   "AUTH LOGIN\r\n";
       $this->docommand();

       $this->in       =   $this->user."\r\n";
       $this->docommand();

       $this->in       =   $this->pass."\r\n";
       $this->docommand();

    // $this->in       =   "MAIL FROM:".$this->from."\r\n";
       $this->in       =   "MAIL FROM:<".$this->from.">\r\n";   //揚(yáng)帆修改
       $this->docommand();

    // $this->in       =   "RCPT TO:".$this->to."\r\n";
       $this->in       =   "RCPT TO:<".$this->to.">\r\n";     //揚(yáng)帆修改
       $this->docommand();

       $this->in       =   "DATA\r\n";
       $this->docommand();

         $this->in       =   $All."\r\n.\r\n";
       $this->docommand();

       $this->in       =   "QUIT\r\n";
       $this->docommand();

       //結(jié)束,關(guān)閉連接

    }
    function docommand()
    {
       socket_write ($this->socket, $this->in, strlen ($this->in));
       $this->debug_show("客戶機(jī)命令:".$this->in);
       $this->result_str = "服務(wù)器應(yīng)答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
       $this->debug_show($this->result_str);
    }
}
?>

php代碼

<?php
//測(cè)試頁(yè)面
include "smtp_mail.php";

//你用這個(gè)類的時(shí)候你修改成你自己的信箱就可以了
$smtp=new smtp_mail("smtp.qq.com","25","yourmail@qq.com","Your password",true);
//如果你需要顯示會(huì)話信息,請(qǐng)將上面的修改成
//$smtp   =   new smtp_mail("smtp.qq.com","25","你的qq.com的帳號(hào)","你的密碼",true);
$smtp->send("yourmail@qq.com","yourmail@qq.com","你好","測(cè)試郵件");
?> 

標(biāo)簽: 代碼 服務(wù)器 網(wǎng)絡(luò)

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:Python3.4 郵件發(fā)送(含帶中文附件)

下一篇:解決跨瀏覽器下PHP下載文件名中的中文亂碼問題