Catching mail and processing it with PHP

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Catching mail and processing it with PHP

Post by phice »

Let's say I have a linux server and I want to catch emails sent to a specific regular expression of an email address (298358.this@domain.com and 895830935.that@domain.com, but not phice@domain.com) and process them with a PHP file. I've seen this done with moblog scripts that will catch emails to a specific email. If it had to be a specific email that would even be fine, but I would much rather prefer a regular expression-based, or something like it, to do this process.

Example: If I send an email to 285803.test@domain.com, I want the linux box to catch that email and process it with a PHP file (body, subject, to, etc. Then I can store that email to whatever I want.

Any idea's going about doing this? If you need any further information, just look at any moblog company. It's the same exact setup.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Related scripts:

http://www.veryfewwords.com/MTpop2blog.txt
http://www.guid.org/oss/pop2blog/pop2blog.pl.txt

Though it's in Perl, would I need to keep it in Perl and how would I go about installing something like that?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

As usual, i would use "fetchmail-ssl" to fecth e-mails from wherever...

And use "procmail" to process them.

I believe .procmailrc would look like (untested)

Code: Select all

##
:0
* ^TO_\d+\.this@domain\.com$\
  ^TO_\d+\.that@domain\.com$
| `php script.php`
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

And how exactly would I go about installing this.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

depends on your distribution...

overhere it's as simple as:

apt-get install fetchmail-ssl
apt-get install procmail
jayloo
Forum Newbie
Posts: 11
Joined: Tue Jun 14, 2005 1:28 pm

Post by jayloo »

Make the incoming mail forward to your script. I have used perl in the past to process the emails but I will be converting this all to php whenever I get around to ordering another server for testing.

php would have to be installed as a CGI though. I may be wrong but you may be able to just install a php command line interpreter.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I'm fairly novice at any of this linux stuff so any examples/code would be great.
Post Reply