php - 如何从 POP3 电子邮件中提取数据?

标签 php email pop3

我使用 PHP 从 POP3 服务器接收电子邮件。我有一个包含标题和正文的原始字符串。如何以类或数组的形式解析标题和正文?

我所拥有的示例:

Return-path: Envelope-to: x@x.de Delivery-date:
Wed, 06 Feb 2013 09:35:37 +0100 Received: from mail by
host6.toxpress.com with spam-scanned (Exim 4.80.1) (envelope-from ) id
1U30Tc-0003sH-LQ for x@x.de; Wed, 06 Feb 2013
09:35:36 +0100 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06)
on host6.toxpress.com X-Spam-Level: X-Spam-Status: No, score=-1.9
required=5.0 tests=BAYES_00,FREEMAIL_FROM,
RCVD_IN_DNSWL_NONE,TVD_SPACE_RATIO autolearn=ham version=3.3.2
Received: from moh3-ve2.go2.pl ([193.17.41.86] helo=moh3-ve1.go2.pl)
by host6.toxpress.com with esmtp (Exim 4.80.1) (envelope-from ) id
1U30Tc-0003rk-2b for x@x.de; Wed, 06 Feb 2013
09:35:32 +0100 Received: from moh3-ve1.go2.pl (unknown [10.0.0.157])
by moh3-ve1.go2.pl (Postfix) with ESMTP id BC734AF611B for ; Wed, 6
Feb 2013 09:34:31 +0100 (CET) Received: from unknown (unknown
[10.0.0.108]) by moh3-ve1.go2.pl (Postfix) with SMTP for ; Wed, 6 Feb
2013 09:34:31 +0100 (CET) Received: from
43.dynamic.chello.pl [89.69.42.127] by poczta.o2.pl with
ESMTP id jtIGfv; Wed, 06 Feb 2013 09:34:31 +0100 Message-ID:
<51121593.3090008@o2.pl> Date: Wed, 06 Feb 2013 09:34:27 +0100 From:
Tomasz Reply-To: tomasz_smykrowski@o2.pl Organization: Tomasz
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101
Thunderbird/20.0a2 MIME-Version: 1.0 To: x@x.de
Subject: adaads Content-Type: text/plain; charset=ISO-8859-1;
format=flowed Content-Transfer-Encoding: 7bit X-O2-Trust: 2, 64
X-O2-SPF: neutral dsadasdsaas .

我想做的事:

echo $from;
echo $replyTo;
echo $date;
echo $body;
echo $subject;
echo $charset;

最佳答案

看看 MIME E-mail message parser类。
根据作者的描述:

This class can be used to parse and decode MIME e-mail messages. It supports decoding single RFC 2822 MIME messages or archives that aggregate multiple messages in the mbox format. The decoded message data is returned as an array that describes one or more messages found in a message file or data string. The bodies of multipart messages can be decoded into distinct sub-messages. The message body data can decoded and saved to separate files, so the class can handle messages larger than the available memory.

关于php - 如何从 POP3 电子邮件中提取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14725067/

相关文章:

php - 可以在不实例化新对象的情况下重新打开 MYSQLI 连接吗

php - 如何在 MSSQL 中存储和检索扩展的 ASCII 字符

java - 使用 javax.mail 在 Java 中发送电子邮件时出现异常

php - 表单值进入数组并将其发送到在 PHP 中不起作用的电子邮件

php - 上传数据并从两个表格中选择它们并显示在同一个 HTML 表格中

php - 将内容插入数据库时​​自动刷新 div 标签

python - 如何使用 django-mailer 定时发送电子邮件

gmail - 如何从gmail下载电子邮件

email - POP3 访问设置

java - Folder.fetch 和 getmessages 之间的区别