php Socket發送郵件驗證郵箱的真實有效性而非格式

phpde 9年前發布 | 941 次閱讀 PHP

<?php

/請尊重別人的勞動成功,請保留此版權信息,謝謝! 作者:小露珠3.3 揚帆修正一點東西:在代碼中已經用注釋注明,本代碼現在向qq發信沒問題~/ set_time_limit(120);

class smtp_mail { var $host; //主機 var $port; //端口 一般為25 var $user; //SMTP認證的帳號 var $pass; //認證密碼 var $debug = false; //是否顯示和服務器會話信息? var $conn; var $result_str; //結果 var $in; //客戶機發送的命令 var $from; //源信箱 var $to; //目標信箱 var $subject; //主題 var $body; //內容 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); //具體用法請參考手冊 if($this->socket) { $this->result_str = "創建SOCKET:".socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("初始化失敗,請檢查您的網絡連接和參數"); } $this->conn = socket_connect($this->socket,$this->host,$this->port); if($this->conn) { $this->result_str = "創建SOCKET連接:".socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("初始化失敗,請檢查您的網絡連接和參數"); } $this->result_str = "服務器應答:<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("請輸入信箱地址");
   }
   if($subject == "") $sebject = "無標題";
   if($body     == "") $body     = "無內容";
   $this->from     =   $from;
   $this->to       =   $to;
   $this->subject   =   $subject;
   $this->body     =   $body;

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

   //以下是和服務器會話
   $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";   //揚帆修改
   $this->docommand();

// $this->in       =   "RCPT TO:".$this->to."\r\n";
   $this->in       =   "RCPT TO:<".$this->to.">\r\n";     //揚帆修改
   $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();

   //結束,關閉連接

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

} ?></pre>

php代碼

<?php
//測試頁面
include "smtp_mail.php";

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

 本文由用戶 phpde 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!