用于阅读电子邮件的 PHP 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11872643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:19:41  来源:igfitidea点击:

PHP Library to read email

phpemailimapswiftmaileremail-client

提问by TheFrack

I currently use the SwiftMailer library to sendemail, but unfortunately it's only for sending, not receiving. I'm wondering... is there a similar library to connect via IMAP to an email account and read the email (IE give me the ability to loop through email). I'm aware there are a set of PHP IMAP functions located here: http://us3.php.net/manual/en/book.imap.php

我目前使用 SwiftMailer 库发送电子邮件,但不幸的是它仅用于发送,而不是接收。我想知道...是否有类似的库可以通过 IMAP 连接到电子邮件帐户并阅读电子邮件(IE 使我能够循环浏览电子邮件)。我知道这里有一组 PHP IMAP 函数:http: //us3.php.net/manual/en/book.imap.php

But my question is, does anybody know of an alternative libarary or IMAP wrapper class for receiving/viewing all your emails?

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

I seriously couldn't find anything, thanks in advance.

我真的找不到任何东西,提前致谢。

回答by Abid Hussain

see below ur:--

见下面你:--

http://www.php.net/mailparse

http://www.php.net/mailparse

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

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

or try it:-

或尝试一下:-

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 protected]';
        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, $i),
                    'structure' => imap_fetchstructure($this->conn, $i)
                );
            }

            $this->inbox = $in;
        }

    }

    ?>

回答by Tomá? Fejfar

Probably the most robust would be using Zend's Email classes:

可能最强大的是使用 Zend 的 Email 类:

Current version

当前版本

Zend 1.12 (no namespaces, good for legacy apps)

Zend 1.12(无命名空间,适用于遗留应用程序)