Receiving and Reading Incoming Mail

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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Receiving and Reading Incoming Mail

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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 ?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Read all of this:
viewtopic.php?t=37333
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Post 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 :)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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