Page 1 of 1

Receiving and Reading Incoming Mail

Posted: Fri Dec 09, 2005 1:25 am
by anjanesh
Hi

Is it possible to run a php script just after a mail has arrived ?

getmail.php

Code: Select all

<?php
$Details = GetMail(); // How do get this done ?
echo $Details['Headers'].'<br/>';
echo $Details['Subject'].'<br/>';
echo $Details['Message'].'<br/>';
?>
1. How do I get $Details = GetMail(); // How do get this done ? done ?
2. How I get getmail.php to run when a new mail has arrived to a particular account ? - [Same domain, server etc]

If 2 is not possible then I can set a cron for every 10 mins or so but how to read the mail contents ?

Thanks

Posted: Fri Dec 09, 2005 9:53 am
by pickle
1. On my Linux server, email is stored in a flat file in a regular format. Needless to say, I can just open that file and rip it apart to get the contents. On my server, email is stored in the file /var/mail/[account name]
2. I think you'll have to go with a cron job for this.

Posted: Fri Dec 09, 2005 10:03 am
by anjanesh
I've seen this before but is this standard ? How can I know the actual path of the mail folder ?
Do all hosting solutions provide mail in var or is this dependent on the distro ?

Posted: Fri Dec 09, 2005 10:24 am
by pickle
It's probably dependant on the host unfortunately. There's probably an elegant way to use the imap functions to login to the mail server and get the contents. SquirrelMail and Ilohamail are written in PHP so they might be a good place to start.

Posted: Fri Dec 09, 2005 11:23 am
by Grim...
Read all of this:
viewtopic.php?t=37333

Posted: Fri Dec 09, 2005 12:23 pm
by anjanesh
Thanks. I was looking for evolt's article.
But according to it, PHP must be installed as module and not CGI.

How do I know if my server is using CGI in phpinfo() ?
Is it not possible to get it working in module ?

Thanks

Posted: Fri Dec 09, 2005 2:11 pm
by trukfixer
if you have root privs on the server, you can set an email alias to pipe the new email into any php or perl or python script. I did this for a email trouble ticket system once, I cant recall the particulars off the top of my head, however but I know it's doable, and it's google-able :)

Posted: Fri Dec 09, 2005 3:44 pm
by josh
like trukfixer said pipe the email, you do this in the configuration files of your mail server, you can actually pipe it to anything that can be run on the command line, so for instance a PHP shell script :-)

Code: Select all

PHP compiled as a CGI binary, not just as an Apache module;
I think you missunderstood the article, as long as you have the CGI binary you're good, regardless if you're using the module