Run PHP script when new email received

Thread Tools Search this Thread
Operating Systems Linux Run PHP script when new email received
# 1  
Old 10-13-2010
Question Run PHP script when new email received

I have been looking around for a solution to this, i have been developing for a wile though am very new to CGI, PHP and a lot of the web based tech.

I have a web site hosted with a cPanel web host.

I am looking to have a script(prefer PHP) to run everytime i get a new email to The script that i was hoping run will update some vars on a sql data base.

I know how to accomplish all the tasks with PHP, the only part i am trying to figure out is how to tell my web server to run the script when a new email is received.

currently running a cron job and would prefer to not run the script every min and only when relevant.

Don't need a solution i like to do my own work, a point in the right learning direction would be nice.
# 2  
Old 10-13-2010
This User Gave Thanks to Neo For This Post:
# 3  
Old 10-13-2010
I think your cron is the right track, but tastes vary.

You can check your mailbox file not empty very easily, and if there is mail, popen a mail command to read it or whatever.

A longer term cron is fine if it just restarts a looping script if not already running.
This User Gave Thanks to DGPickett For This Post:
# 4  
Old 10-13-2010
don't want to have a looping solution. Already doing that in the mean time and am trying to move to something a little more real time. How would i set the cron to check if the script is running or not?

found something else on procmail another post stated
'got the result i'm looking for through .procmailrc in the ~/ directory of the user'
if that is what you are referring to then i can not find ~/ dir.
Just a reminder that i am using a cheepo web host. so i dont have root access.

I found this post that might be in the right direction
though i am not aloud to post the URL at the moment
this is the there sugestion
Look at using the /etc/aliases file - you can pipe the incoming message to a specific user into a program (or script)

looking @ my /etc/aliases is not there. So not sure how i would continue to use the above solution

Last edited by iKris; 10-13-2010 at 05:15 PM..
# 5  
Old 10-13-2010
This User Gave Thanks to Neo For This Post:
# 6  
Old 10-13-2010
in my root there is no .forward or in the etc or in any of the domain dir in the etc
should i just make one? then what should i do with it? or what should i read to know what i can do with it?

I know i said i am not looking for a solution, still true, but i could use a little more insight as i am newb to this world.

Thanks again for all your help thus far
# 7  
Old 10-13-2010
Try looking for /etc/mail/aliases
create a line that looks like:
recipient: <tab> recipient, |/usr/bin/myprocess
remember that myprocess had to process all the lines of the email including the header records.
I like to keep the email in the recipient mailbox as well so that the original email is still available if debugging is required.
run 'newaliases' after editing the file.

Last edited by jgt; 10-13-2010 at 08:58 PM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Adding a blank line in between two O/Ps in tabular format which gets received over email

Hi Guys, I am stuck in between and seeking help here. Requirement: A script that will run every morning which will connect to Mysql database and run the query to inform us about the holidays (it will also check if there were any holidays during last 2 business days). So the three queries are... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

How to check email with attachment received or not from UNIX shell script?

Hello Guys, Here is the requirement!! I want to check the mail with attachment received or not through unix scripting. And send an notification email when mail with attachment already received. Any thoughts on this is much appreciated!! Regards, Harry (0 Replies)
Discussion started by: dharry2017
0 Replies

4. Forum Support Area for Unregistered Users & Account Problems

No activation email received

I have tried to register today with the username BatterBits, but have not received the activation email I do not live in any of the restricted countries - unless the UK has suddenly become a threat! I'd be grateful if you would assist. many thanks Ian (2 Replies)
Discussion started by: unregistered
2 Replies

5. Shell Programming and Scripting

Run a script when I receive an email

Hi expert I wish to start a shell script when I receive an email. I modified the aliases file and I add this string as400nag: "|/home/nag-script/startstop/ The solution works . When the as400nag user receive an email the /home/nag-script/startstop/ starts .but... (3 Replies)
Discussion started by: emi65
3 Replies

6. UNIX for Advanced & Expert Users

problem on email sent but not received

hi.. I have the porblem where the email was sent but not received by users.. The message as below:- Dec 16 11:42:04 isp postfix/smtp: A80042B4B: to=<>,, delay=890, delays=0.17/0.02/31/859, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued... (1 Reply)
Discussion started by: bh_hensem
1 Replies

7. Forum Support Area for Unregistered Users & Account Problems

no email received

I have tried to register and got a message saying an email would be sent but no email has turned up. Could you try again please? (1 Reply)
Discussion started by: lookingfor help
1 Replies

8. UNIX for Dummies Questions & Answers

run a script from incoming email

hi I have a bit of a problem i need help with. I have a script that runs no problems when i run it manually. as soon as i stick in tester: /app/scripts/ into /etc/aliases & try to run it by sending a mail it doesnt work. the output files are owned by daemon, which i dont like & think... (7 Replies)
Discussion started by: jojo77
7 Replies

9. UNIX for Advanced & Expert Users

Problem with mailx - Can execute but email not received

Hi, I tried running mailx command like this: sadm@bioinfo-z:~$ mailx Subject: testgmail Some content. . EOT As you can see although it is successfuly executed. But still I can't receive email at my account. What is the cause? (9 Replies)
Discussion started by: monkfan
9 Replies

10. Forum Support Area for Unregistered Users & Account Problems

Did not received any email for account activation

hi I did not received any such email for account activation nor i am able to see any status in my profile. Am i missing anything?? :confused: Please help Appreciated. (0 Replies)
Discussion started by: bhush782003
0 Replies
Login or Register to Ask a Question

Featured Tech Videos