用户实现邮箱注册时,避免企业发送的邮件被送入垃圾箱,需要用户发送任意一封邮件到企业邮箱进行注册,然后由企业定时任务完成邮箱认证
例如使用163 的pop3 协议
先开启:
使用socket编程就很随意搞定
<?php /** 用户往[email protected]发送一封邮件,内容随意 系统就可以把此用户激活 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 = 'byfworld'; protected $pass = '18790529086'; 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(); }