PHP:从 POP3 或 IMAP 下载传入的电子邮件,解析它,并在服务器上将其标记为已读/删除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1450490/
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
PHP: Download incoming email from POP3 or IMAP, parse it, and mark it as read/delete on server
提问by Pep
I'm trying to add incoming email to my web application. It's built on CodeIgniter and PHP, and as far as I can tell I haven't found any CI libraries to do this.
我正在尝试将传入的电子邮件添加到我的 Web 应用程序中。它建立在 CodeIgniter 和 PHP 之上,据我所知,我还没有找到任何 CI 库来做到这一点。
What I'd like to do is have a controller that connects to my mail box, via POP3 or IMAP, and retrieves the message, parses it then removes it from the server.
我想要做的是有一个控制器,通过 POP3 或 IMAP 连接到我的邮箱,并检索消息,解析它然后将其从服务器中删除。
Piping mail from postfix/etc isn't going to work on my server setup.
从 postfix/etc 传送邮件在我的服务器设置中不起作用。
Any suggestions would be immensely helpful.
任何建议都会非常有帮助。
Thanks!
谢谢!
回答by Leprechaun
$mb = imap_open("{host:port/imap}","username", "password" );
$messageCount = imap_num_msg($mb);
for( $MID = 1; $MID <= $messageCount; $MID++ )
{
$EmailHeaders = imap_headerinfo( $mb, $MID );
$Body = imap_fetchbody( $mb, $MID, 1 );
doSomething( $EmailHeaders, $Body );
}
回答by Antony
For a more independent approach you could build a Third party plugin with Zend framework (https://docs.zendframework.com/zend-mail/read/). I have used their ACL modules within Codeigniter and is a good way of getting the best of both frameworks.
对于更独立的方法,您可以使用 Zend 框架 ( https://docs.zendframework.com/zend-mail/read/)构建第三方插件。我在 Codeigniter 中使用了他们的 ACL 模块,这是充分利用这两个框架的好方法。
This also allows you to parse the emails and extract attachments etc.
这还允许您解析电子邮件并提取附件等。

