首頁 > 後端開發 > php教程 > php Socket寄送郵件驗證信箱的真實有效性而非格式

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

WBOY
發布: 2016-07-25 08:45:06
原創
1076 人瀏覽過
?>
  1. /*請尊重別人的勞動成功,請保留此版權訊息,謝謝!
  2. 作者:小露珠3.3
  3. 揚帆修正一點東西:在程式碼中已經用註解註明,本程式碼現在向qq發信沒問題~
  4. */
  5. set_time_limit(120);
  6. class smtp_mail
  7. {
  8. var $host; //主機
  9. var $port; //連接埠一般為25
  10. var $user; //SMTP認證的帳號
  11. var $pass; //認證密碼
  12. var $debug = false; //是否顯示和伺服器會話資訊?
  13. var $conn;
  14. var $result_str; //結果
  15. var $in; //客戶機發送的命令
  16. var $from; //來源信箱
  17. var $to; / /目標信箱
  18. var $subject; //主題
  19. var $body; //內容
  20. function smtp_mail($host,$port,$user,$pass,$debug=false)
  21. {
  22. $this->host = $host;
  23. $this->port = $port;
  24. $this->user = base64_encode($user);
  25. $this->pass = base64_encode( $pass);
  26. $this->debug = $debug;
  27. $this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP); //具體用法請參考手冊
  28. if($this-> socket)
  29. {
  30. $this->result_str = "建立SOCKET:".socket_strerror(socket_last_error());
  31. $this->debug_show($this->result_str);
  32. $this->debug_show($this->result_str);
  33. }
  34. else
  35. {
  36. exit("初始化失敗,請檢查您的網路連線與參數");
  37. }
  38. $this->conn = socket_connect($this->socket,$this- >host,$this->port);
  39. if($this->conn)
  40. {
  41. $this->result_str = "建立SOCKET連線:".socket_strerror(socket_last_error());
  42. $this->debug_show($this->result_str);
  43. }
  44. else
  45. {
  46. exit("初始化失敗,請檢查您的網路連線與參數");
  47. }
  48. $this->result_str = "伺服器回應:".socket_read ($this->socket, 1024)."";
  49. $this->debug_show($ this->result_str);
  50. }
  51. function debug_show($str)
  52. {
  53. if($this->debug)
  54. {
  55. echo $str."rn";
  56. }
  57. }
  58. function send($from,$to,$subject,$body)
  59. {
  60. if($from == "" || $to == "")
  61. {
  62. exit("請輸入信箱位址");
  63. }
  64. if($subject == "") $sebject = "無標題";
  65. if ($body == "") $body = "無內容";
  66. $this->from = $from;
  67. $this->to = $to;
  68. $this->subject = $ subject;
  69. $this->body = $body;
  70. //揚帆修改部分程式碼
  71. $All = "From:from.">rn";
  72. $All .= "To:to.">rn";
  73. $All .= "Subject:".$this->subject."rnrn";
  74. $All .= $this->body;
  75. /*
  76. 如過把$All的內容再加處理,就可以實現發送MIME郵件了
  77. 不過還需要加很多程序
  78. */
  79. //以下是和伺服器會話
  80. $this->in = "EHLO HELOrn";
  81. $this->docommand();
  82. $this->in = "AUTH LOGINrn";
  83. $this->docommand();
  84. $this->in = $this->user."rn";
  85. $this->docommand();
  86. $this->in = $this->pass."rn";
  87. $this->docommand();
  88. // $this->in = "MAIL FROM:". $this->from."rn";
  89. $this->in = "MAIL FROM:from.">rn"; //揚帆修改
  90. $this->docommand( );
  91. // $this->in = "RCPT TO:".$this->to."rn";
  92. $this->in = "RCPT TO:to.">rn"; //揚帆修改
  93. $this->docommand();
  94. $this->in = "DATArn";
  95. $this->docommand() ;
  96. $this->in = $All."rn.rn";
  97. $this->docommand();
  98. $this->in = "QUITrn";
  99. $this->docommand();
  100. //結束,關閉連線
  101. }
  102. function docommand()
  103. {
  104. socket_write ($this-this>socket , $this->in, strlen ($this->in));
  105. $this->debug_show("客戶機指令:".$this->in);
  106. $this->result_str = "伺服器回應:".socket_read ($this->socket, 1024)."";
  107. $this->debug_show($this->result_str);
  108. }
  109. }
?>
複製程式碼

php程式碼

  1. //測試頁
  2. include "smtp_mail.php";
  3. //測試頁
  4. 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","你好","測試郵件");
複製程式碼

而非, 寄信, php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板