使用PHP捕获和管理电子邮件数据 [英] Capture and Manage Email Data with PHP
问题描述
我正在寻找一种使用PHP捕获和管理电子邮件数据的方法。基本上,我想做的是捕获电子邮件中的所有数据,然后将这些数据操作到我的规范。
I'm looking for a way to capture and manage email data using PHP. Basically, what I want to do is capture all the data in an email and then manipulate this data to my specification.
例如,我发送一封包含.zip文件附件到myemail@myproject.com,我想要能够:
For example, say, I send an email containing a .zip file attachment to myemail@myproject.com, I want to be able to:
- 获取附件并将其放在特定文件夹中在我的网站上
- 获取电子邮件的文本内容
- 获取电子邮件的主题
- 获取发件人的信息,即电子邮件地址
- Get the attachment and place it in a specific folder on my site
- Get the text content of the email
- Get the subject of the email
- Get the sender's info i.e. email address
任何人都知道如何使用PHP高效地完成此操作。我正在使用LAMP。
Anyone know how I can get this done efficiently with PHP. I'm using LAMP by the way.
谢谢。
推荐答案
从PEAR开始 Mail_mimeDecode
。你所要做的是雄心勃勃,但可以做到。
Start with PEAR Mail_mimeDecode
. What you are looking to do is ambitious but can be done.
基本上你将要做的是:
指示您的MTA将邮件从地址传递到管道到您的PHP脚本。 Postfix和Sendmail可以处理以下别名:
Instructing your MTA to deliver mail from an address to a pipe into your PHP script. Postfix and Sendmail can handle this with an alias like:
myemail: "|/path/to/your/parsingscript.php"
- 分析MIME电子邮件的部分
- 在从base64(或其他编码)解码后查找和存储附件
- 解析标题。
您的PHP脚本可能会从STDIN读取电子邮件,然后将该字符串传递到 mimeDecode
,该对象包含所有MIME部分。
Your PHP script will likely read the email message from STDIN and then pass the string to mimeDecode
, which creates an object containing all the MIME parts.
假设你的消息是从STDIN 收到 $ str
,这样可以让你开始:
Assuming your message was received into $str
from STDIN, something like this gets you started:
$mime = Mail_mimeDecode::decode(array('include_bodies'=>TRUE, 'decode_headers'=>TRUE, 'decode_bodies'=>TRUE, 'input'=>$str));
// get the recipient To address:
$to = $mime->headers['to'];
这篇关于使用PHP捕获和管理电子邮件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!