Page 1 of 1

Catching mail and processing it with PHP

Posted: Sun Jun 05, 2005 1:31 am
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.

Posted: Sun Jun 05, 2005 1:32 am
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?

Posted: Sun Jun 05, 2005 4:33 am
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`

Posted: Sun Jun 05, 2005 12:18 pm
by phice
And how exactly would I go about installing this.

Posted: Sun Jun 05, 2005 12:38 pm
by timvw
depends on your distribution...

overhere it's as simple as:

apt-get install fetchmail-ssl
apt-get install procmail

Posted: Tue Jun 14, 2005 2:22 pm
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.

Posted: Tue Jun 14, 2005 2:25 pm
by phice
I'm fairly novice at any of this linux stuff so any examples/code would be great.