shawngoldw Posted June 9, 2010 Share Posted June 9, 2010 Hello, I need to run a php script whenever my server receives email. It has been recommended to me to use procmail to trigger the php script. I have zero experience with procmail and need some guidance I just need a simple procmail script which will run a php script every time an incoming email is received. If someone could either show me the few lines I need or point me where to find them it would be greatly appreciated. Thanks, Shawn Quote Link to comment https://forums.phpfreaks.com/topic/204307-procmail-to-php/ Share on other sites More sharing options...
trq Posted June 9, 2010 Share Posted June 9, 2010 There should be plenty of examples of this around on the net, but basically, in ~/.procmailrc you use patterns to match email addresses (or subject lines) and determin what to do with the email (generally sending them to a different inbox). This can be used to pipe an email to a php script. eg; :0: * ^To.whatever@foo.com | /usr/local/bin/script.php Quote Link to comment https://forums.phpfreaks.com/topic/204307-procmail-to-php/#findComment-1070102 Share on other sites More sharing options...
shawngoldw Posted June 9, 2010 Author Share Posted June 9, 2010 Thank you very much. I have a couple questions. what does the second line do? When you say "pipe an email to a php script" do you mean that the email gets passed into the script? or just that the php script gets called? If it's the first case, how do you access the passed in email from within php? Quote Link to comment https://forums.phpfreaks.com/topic/204307-procmail-to-php/#findComment-1070111 Share on other sites More sharing options...
trq Posted June 9, 2010 Share Posted June 9, 2010 The second line is where the pattern matching happens. You'll find plenty of tutorials around for this. The contents of the email will show up in the standard in of your php script. Quote Link to comment https://forums.phpfreaks.com/topic/204307-procmail-to-php/#findComment-1070126 Share on other sites More sharing options...
shawngoldw Posted June 9, 2010 Author Share Posted June 9, 2010 ohhh the second line is a regular expression.... thought it looked familiar. so if I want it to run for every email I just leave out the second line? and pardon my lack of knowledge, but what would the "standard in" be? Quote Link to comment https://forums.phpfreaks.com/topic/204307-procmail-to-php/#findComment-1070135 Share on other sites More sharing options...
trq Posted June 9, 2010 Share Posted June 9, 2010 I believe you would also need to use the global procmailrc file not just the one within your ~/ directory. Quote Link to comment https://forums.phpfreaks.com/topic/204307-procmail-to-php/#findComment-1070138 Share on other sites More sharing options...
trq Posted June 9, 2010 Share Posted June 9, 2010 Oh, and no, you can't leave that line blank. You would need a pattern that matches all. See http://www.perlcode.org/tutorials/procmail/regular_expressions.pod As for standard in, see http://php.net/manual/en/features.commandline.io-streams.php Quote Link to comment https://forums.phpfreaks.com/topic/204307-procmail-to-php/#findComment-1070141 Share on other sites More sharing options...
shawngoldw Posted June 10, 2010 Author Share Posted June 10, 2010 :0: * ^.* | /usr/local/bin/script.php Would this work to match everything? My reasoning is . for every character and * for 0 or more matches Thanks for all the help Quote Link to comment https://forums.phpfreaks.com/topic/204307-procmail-to-php/#findComment-1070178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.