php收取郵件

來源:互聯網
上載者:User

標籤: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收取郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.