PHP库读取电子邮件

前端之家收集整理的这篇文章主要介绍了PHP库读取电子邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前使用 SwiftMailer库发送电子邮件,但不幸的是它仅用于发送,而不是接收.我想知道…是否有类似的库通过IMAP连接到电子邮件帐户并阅读电子邮件(IE让我能够循环通过电子邮件).我知道这里有一组 PHP IMAP函数http://us3.php.net/manual/en/book.imap.php

但我的问题是,是否有人知道用于接收/查看所有电子邮件的替代图书馆或IMAP包装类?

事先谢谢,我真的找不到任何东西.

见下面你的: –

http://www.php.net/mailparse

http://garrettstjohn.com/entry/reading-emails-with-php/

或试试: –

PHP阅读电子邮件

<?PHP

    class Email_reader {

        // imap server connection
        public $conn;

        // inBox storage and inBox message count
        private $inBox;
        private $msg_cnt;

        // email login credentials
        private $server = 'yourserver.com';
        private $user   = 'email@yourserver.com';
        private $pass   = 'yourpassword';
        private $port   = 143; // adjust according to server settings

        // connect to the server and get the inBox emails
        function __construct() {
            $this->connect();
            $this->inBox();
        }

        // close the server connection
        function close() {
            $this->inBox = array();
            $this->msg_cnt = 0;

            imap_close($this->conn);
        }

        // open the server connection
        // the imap_open function parameters will need to be changed for the particular server
        // these are laid out to connect to a Dreamhost IMAP server
        function connect() {
            $this->conn = imap_open('{'.$this->server.'/notls}',$this->user,$this->pass);
        }

        // move the message to a new folder
        function move($msg_index,$folder='INBox.Processed') {
            // move on server
            imap_mail_move($this->conn,$msg_index,$folder);
            imap_expunge($this->conn);

            // re-read the inBox
            $this->inBox();
        }

        // get a specific message (1 = first email,2 = second email,etc.)
        function get($msg_index=NULL) {
            if (count($this->inBox) <= 0) {
                return array();
            }
            elseif ( ! is_null($msg_index) && isset($this->inBox[$msg_index])) {
                return $this->inBox[$msg_index];
            }

            return $this->inBox[0];
        }

        // read the inBox
        function inBox() {
            $this->msg_cnt = imap_num_msg($this->conn);

            $in = array();
            for($i = 1; $i <= $this->msg_cnt; $i++) {
                $in[] = array(
                    'index'     => $i,'header'    => imap_headerinfo($this->conn,$i),'body'      => imap_body($this->conn,'structure' => imap_fetchstructure($this->conn,$i)
                );
            }

            $this->inBox = $in;
        }

    }

    ?>
原文链接:https://www.f2er.com/php/135510.html

猜你在找的PHP相关文章