Pipe ALL incoming emails to PHP script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Pipe ALL incoming emails to PHP script

Post 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.
User avatar
bmcewan
Forum Commoner
Posts: 55
Joined: Wed Jun 02, 2004 7:19 am
Location: West Yorkshire, UK.

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
bmcewan
Forum Commoner
Posts: 55
Joined: Wed Jun 02, 2004 7:19 am
Location: West Yorkshire, UK.

Post 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
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post 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
Post Reply