標籤:des blog http io ar os sp for on
有的網站用這種方式來啟用使用者。讓你用註冊郵箱給指定的郵箱發信;如馬鈴薯;
/*讓使用者往公司的企業郵箱發信,收到後給他啟用
思路:
用php+POP協議收取信件(php+socket編程)
收到信件,分析寄件者,並啟用該使用者
讓系統每個幾分鐘運行一次,用linux的crontab做定時任務
*/
telnet 收取信件
ctrl +】 斷行符號
輸入user pass
top 1 5 是第一封郵件的前5行的意思
如果要提取寄件者資訊,只取得1行資訊就夠了,top 1 1
<?php/****自學it網 高端PHP培訓論 壇: http://www.zixue.it微 博: http://weibo.com/Yshiba****//**使用者往php0620@163.com發送一封郵件,內容隨意系統就可以把此使用者啟用1: 用PHP+POP3協議收取信件(PHP+SOCKET編程)2: 收到信件,分析寄件者,並啟用該使用者3: 每隔幾分鐘,自動運行一次(linux下用crontab做定時任務)**/class pop3 { const CRLF = "\r\n"; protected $host = ‘pop3.163.com‘; protected $port = 110; protected $errno = -1; protected $errstr = ‘‘; protected $user = ‘xxxxxxxxx‘; protected $pass = ‘*******‘; protected $fh = NULL; // 放置串連資源 // 串連伺服器 public function conn() { $this->fh = fsockopen($this->host,$this->port,$this->errno,$this->errstr,3); } public function login() { fwrite($this->fh,‘user ‘ . $this->user . self::CRLF); if(substr($this->getLine(),0,3) != ‘+OK‘) { throw new Exception("使用者名稱不正確"); } fwrite($this->fh,‘pass ‘ . $this->pass . self::CRLF); if(substr($this->getLine(),0,3) != ‘+OK‘) { throw new Exception("密碼不正確"); } } /* // 查詢一共有多少郵件,便於迴圈取每一封郵件 public function getCnt() { fwrite($this->fh,‘stat‘ . ‘ ‘ . self::CRLF); $tmp = explode(‘ ‘,$this->getLine()); return $tmp[1]; }*/ // 查詢出所有的郵件發信人 public function getAll() { fwrite($this->fh,‘top 1 1‘ . self::CRLF); $post = array(); while( stripos(($row = fgets($this->fh)),‘from:‘) === false) { } $post[] = $row; return $post; } protected function getLine() { return fgets($this->fh); } // 發送使用者名稱+密碼 登陸 // 擷取郵件}$pop = new pop3();try { $pop->conn(); $pop->login(); echo ‘發信人是‘;print_r($pop->getAll());} catch(exception $e) { echo $e->getMessage();}// 擷取收集人,之後 串連mysql,根據email,啟用該使用者
php收取郵件