Page 1 of 1

Pipe ALL incoming emails to PHP script

Posted: Thu Aug 31, 2006 12:02 am
by aliasxneo
I have been trying to make a basic mail client with PHP for quite some time, and I always seem to fail. I have tryed numerous things, but I have found nothing that works, but i'm not giving up.

I have private hosting from a good friend, comes right off a datacenter in Maryland. I of course do not have root access to my hosting, so that's a serious disadvantage. What I want to do is have ALL incoming mail piped to a php script where I can store it in a MySql database. I believe my current server is using SendMail.

I have tryed creating a .forward file to pipe it to a php script, but it never worked, not to mention it only allowed it to work for one email address, when I need it to any address that's directed to my domain.

So, do we have any experts in here that have ever created a system like this? I see them everywhere, I figured it should be possible with PHP.

Posted: Thu Aug 31, 2006 4:30 am
by bmcewan
Food for thought.....

imap to retrieve the mail and sort it based on recipient in the header.

You will want to check if php has been compiled with this library.

Posted: Thu Aug 31, 2006 6:16 am
by Chris Corbyn
Use Exim, write a system filter like this:

Code: Select all

pipe "/usr/bin/php yourscript.php $sender_address $recipients $h_Subject: $message_body  $message_id"
finish

Posted: Thu Aug 31, 2006 7:47 am
by bmcewan
d11wtq wrote:Use Exim, write a system filter like this:

Code: Select all

pipe "/usr/bin/php yourscript.php $sender_address $recipients $h_Subject: $message_body  $message_id"
finish
Much tidier thoughts :D

Posted: Thu Aug 31, 2006 7:56 am
by jamiel
Perhaps you can ask your admin to do it for you.

You need to setup an alias for your user in /etc/aliases (or /etc/mail/aliases)

Code: Select all

myuser:     "| myscript.php"
And as a security precaution most sendmail configurations don't allow you to pipe to untrusted scripts. To make it trusted you need to create a symlink to smrsh

Code: Select all

ln -s myscript.php /etc/smrsh/myscript.php