用于读取电子邮件的 PHP 库

2024-01-24

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

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

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


见下文:--

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/

或尝试一下:-

使用 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] /cdn-cgi/l/email-protection';
        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;
        }

    }

    ?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

用于读取电子邮件的 PHP 库 的相关文章

  • 在 Windows 上查看 PHP 文件夹

    我正在编写一个简单的 PHP 脚本来监视文件夹及其子文件夹的任何更改 新文件 修改 删除 然后执行操作 我将使用 Windows 上的命令行运行此脚本php f script php 我一直在寻找一种在 Windows 上观看具有 PHP
  • PHPunit - 错误

    当 PHPunit 框架不希望发生的错误发生时 测试会停止 PHP 会抛出错误 但 PHPunit 不会记录这是一个错误 我如何确保 PHPunit 将其记录为错误 免责声明 我是 PHPUnit 的新手 我也试图弄清楚 发生错误时会发生什
  • Magento 中的子域 htaccess 问题

    public html www domain com public html subdomain subdomain domain com public html htaccess public html subdomain htacces
  • 准备好的语句需要 0 个参数,给定 1 个参数..,使用 php 手册示例 [重复]

    这个问题在这里已经有答案了 我直接从 php 手册示例中获取了这个 它几乎与我需要的相同 但我仍然收到此错误 有人可以告诉我我错过了什么吗 stmt link gt prepare SELECT obitBody Photo FROM tn
  • PHP 用星号替换所有字符

    假设我有一个字符串形式的密码 password thisisaplaintextpassword 我怎样才能把它变成下面的样子 password 我想通过电子邮件向用户发送他们的帐户详细信息 但不想发送整个内容 Use 字符串重复 http
  • 压缩 zend Framework 2 的 html 输出

    我目前正在 PHP 5 4 4 上使用 Zend Framework 2 beta 开发个人 web 应用程序以用于自学目的 我想知道是否可以在 html 输出发送到浏览器之前拦截它 以便通过删除所有不必要的空格来缩小它 我怎样才能在ZF2
  • PHP解析xml文件错误

    我正在尝试使用 simpleXML 来获取数据http rates fxcm com RatesXML http rates fxcm com RatesXML Using simplexml load file 我有时会遇到错误 因为这个
  • 重复使用相同的卷曲手柄。性能大幅提升?

    在 PHP 脚本中 我对不同的 URL 执行了许多不同的curl GET 请求 一百个 将重复使用来自curl init提高性能 还是与请求的响应时间相比可以忽略不计 我这么问是因为在当前的架构中保持相同的句柄并不容易 交叉发布自我应该关闭
  • 覆盖供应商自动加载编辑器

    有没有办法让您创建的自动加载文件在调用供应商自动加载之前运行 我们似乎遇到了 SimpleSAML 的自动加载覆盖我们创建的自动加载文件之一的问题 我是 Composer 的新手 似乎无法在网上找到任何解决方案 我尝试将我们的自动加载文件包
  • Zend IMAP 搜索和过滤器

    我如何使用 Gmail 中的过滤器进行搜索 就像获取带有特定标签的电子邮件列表或来自特定电子邮件地址的邮件列表一样 我无法在文档中找到它 注意 我使用 oAuth 进行身份验证 我希望这与搜索无关 Gmail 上的标签实际上是 从 IMAP
  • 使用 PHP 将值插入可编辑 PDF,并保持可编辑状态

    我有一个带有可编辑字段的 PDF 我希望将 HTML 表单中的值传递到此 PDF 中 我尝试过使用 FPDF 并且它有效 但是将值传递到 PDF 后 pdf 中的字段不再可编辑 另一个缺点是 在将值传递到 PDF 时 我们必须为每个字段指定
  • strlen()==0 和empty()之间有区别吗?

    我正在查看其他人编写的一些表单验证代码 我看到了这个 strlen 0 当测试表单变量是否为空时 我使用empty 功能 一种方法比另一种方法更好吗 它们在功能上等效吗 strlen是获取字符串中的字符数 同时empty用于测试变量是否为空
  • Node.js 中的 PHP exit()/die() 等价物是什么

    什么是 PHP die http www php net manual de function die php http www php net manual de function die php 在 Node js 中等效吗 https
  • 如何以编程方式获取 WooCommerce 中的所有产品?

    我想获取 WooCommerce 中的所有产品数据 产品 sku 名称 价格 库存数量 可用性等 我可以使用 wp query 来做到这一点吗 这样你就可以通过 wp query 获取所有产品 global wpdb all product
  • 使用 PHP 的 Google Glass GDK 身份验证

    我正在尝试点击此链接来验证 GDK 中的用户 https developers google com glass develop gdk authentication https developers google com glass de
  • 运行PHPUnit测试时如何避免内部调用函数?以及如何设置内部性能的模拟数据?

    我有一个类 Receipt php
  • 在 Woocommerce 购物车中设置最小小计金额

    我正在尝试将最低订单金额设置为 25 美元 到目前为止 我找到了这段代码 如果未达到最低限度 它似乎可以阻止结账 但它使用的小计包含税费 我需要在总计中排除税费 add action woocommerce checkout process
  • 如何编写在正文中包含锚标记的 Zend Framework URL?

    使用 Zend Framework 中设置的标准 MVC 我希望能够显示始终具有锚点的页面 现在我只是在 phtml 文件中添加一个带有 anchor 的无意义参数
  • 如何通过 UNIX mailx 命令发送电子邮件?

    如何通过 UNIX 发送电子邮件mailx命令 一个例子 echo something mailx s subject email protected cdn cgi l email protection 发送附件 uuencode fil
  • 在 PHP 中模拟 jQuery.ajax 请求

    我必须在 PHP 中模拟 AJAX 请求 就像在 jQuery 中一样 我当前的代码在这里 原始 AJAX 调用 不得修改 ajax type POST url someFile php data data success function

随机推荐