是否可以在PHP中编写电子邮件解析器? [英] Is it possible to write an email parser in PHP?

查看:132
本文介绍了是否可以在PHP中编写电子邮件解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP技能是中间的,但我想尝试实现这个:

My PHP skills are intermediate, but I want to try to implement this:

我有一个网站为本地爵士音乐家。我希望他们能够在他们的个人资料页面添加即将到来的演出。我希望他们能够通过电子邮件发送这些更新,像我可以添加任务到我的在线待办事项列表。

I have a site for local jazz musicians. I would like them to be able to add upcoming gigs to their profile page. I would like them to be able to send these updates in by email, like I can add tasks to my online Todo list.

所以我需要解析电子邮件我的帐户在服务器上。

So I need to parse emails that land in my account on the server.

我认为它的执行标准格式。 。和我在想

I think its fair to enforce a standard format . .and I was thinking

(In subject)NEWGIG   [[or maybe set up a separate "newgig@mySite.com" email account for gig updates only]]

TITLE>My next super gig<TITLE
DATE>03/10/2012<DATE
DESC>Here is some supplementary information<DESC
LINK>www.hereIsTheVenue.com<LINK

将添加演出和确认电子邮件发出。

The gig would be added and a confirmation email sends out.

这有多难?是否可以?我想我可以做所有的测试解析和SQL,等..但我没有太多的经验与邮件,似乎有很多fiddly位值得注意。

How difficult is this to do? Is it possible? I think I can do all of the test parsing and SQL, etc .. but I don't have much experience with mail and it seems like there are a lot of "fiddly bits" to watch out for.

任何人都可以确认这是可行的,我开始之前?任何提示或需要注意的事项?

Can anyone confirm that this is doable before I start? Any tips or things to look out for?

BTW - 我在做电子邮件解析器,因为我想要超级容易使用。音乐家非常懒惰,所以如果我可以让他们在他们的电子邮件(他们通常得到确认)发布一个gig,那么它节省了他们去网站,登录,去他们的帐户等的麻烦。 p>

BTW - I'm doing the email parser because I want it to be super easy to use. Musicians are notoriously lazy so if I can let them post a gig right out of their email (where they are usually getting confirmation) then it saves them the hassle of going to the site, logging in, going to their account, etc.

推荐答案

是的,它是可行的。所有您需要的是访问具有smtp端点的服务器。例如postfix或exim或任何其他监听传入电子邮件。
您需要配置此软件将传入邮件作为明文传递到您的脚本或程序,可以处理来自 stdin 的输入。

Yes, it is doable. All you need is access to a server with an smtp endpoint. something like postfix or exim or anything other that listens to incoming email. you need to configure this software to pass incoming mail as plaintext into a script or program of yours which can handle the input from stdin.

最简单的方法是创建一个指向脚本的新电子邮件别名。我在我的 / etc / aliases 文件中有很多条目,如下所示:

the easiest way is to create a new email alias which points to a script. i have plenty of entries in my /etc/aliases file which look like this:

userpart: "|/usr/bin/php -f /path/to/some/script.php"

每当电子邮件到达此地址时都会触发此操作: userpart@this.server.example

this gets triggered whenever an email arrives on this address: userpart@this.server.example

脚本本身读取这样的输入

the script itself reads the input like this

$fp = fopen('php://stdin','r');
    while (!feof($fp)) {
            $input .= fgets($fp);
    }
fclose($fp);

您可能会发现使用现有的MIME解析器很有用,因为输入可以是任何现代MUA想想。

you might find the use of an existing MIME Parser useful since the input could be anything a modern MUA could think of.

这篇关于是否可以在PHP中编写电子邮件解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆