FrozenWire
05-07-2008, 11:19 AM
I am currently working on a website that relies on processing incoming text emails to a specific address. I wish to run through these messages and process them based on their content. I have researched online and come across a bunch of programs that create sub pop servers and such that process all incoming mail but at the current moment, I am looking for a much simpler approach.
How can I process specific accounts on an existing mail server?
For example, if a message comes in on incoming@site.com, how can I just forward that email to incoming.php on the server and process it?
Thanks in advance.
ThatScriptGuy
05-07-2008, 12:17 PM
Just create a forwarder to |/home/user/file.php for that specific address.
FrozenWire
05-07-2008, 01:47 PM
any experience on how PHP handles that? Is it similar to a form submission where I need to parse through it?
For example, when the email comes into incoming@site.com and it gets pushed to script.php, how would the script reference the email?
Thanks
cygnusd
05-09-2008, 12:45 AM
If you're using sendmail, you'd want to the following (more or less):
1. add an alias to your /etc/aliases. incoming: "|/home/myuser/src/myscript"
2. add a symlink to /etc/smrsh pointing to your myscript. sendmail requires this to prevent arbitrary scripts from running. check your executable permissions to myscript (which I usually set to 755, both the actual script and the symlink).
Note that myscript can be written using anything (php, perl, bash, C, anything), as long as it can read from STDIN.
By creating a pipe, your script needs to read the "raw" email (in mime format). Many modules are available to parse and convert mime format into objects/data structures that are easier to deal with while programming.
BurakUeda
05-09-2008, 03:07 AM
You cannot send and email to a php script. But you can run a script when a message arrived to a certain address.
If you are going to use PHP, check these:
PHP IMAP Functions (http://php.net/imap)
PEAR NET_POP3 Functions (http://pear.php.net/manual/en/package.networking.net-pop3.php)
Zend_Mail (http://framework.zend.com/manual/en/zend.mail.html)
Latter two needs to be installed to your server.