0

I have a procmail script set up which pipes to a PHP script when an email subject line matches:

:0
* ^[email protected]|^Subject.*(REMOVE|Undelivered Mail)
| /usr/bin/php -f /var/www/somefolder/script.php

Is there a way to pass a parameter to the PHP script via the procmail command, like you do with query-string parameters? I've tried the following, and neither works:

| /usr/bin/php -f /var/www/somefolder/script.php?iscron=1
| /usr/bin/php -f /var/www/somefolder/script.php --iscron=1

I want the PHP script to be able to check what is triggering it. Thanks for any help.

4
  • This is rather unclear; are you asking how to distinguish which part of the Procmail regex matched (which my answer attempts to solve) or how to parse arguments in PHP (which I imagine must be thorougly answered by existing questions)? Please edit to clarify.
    – tripleee
    Commented Jun 24 at 11:20
  • I edited a bit, hope that made it clearer. @ken-lee answered the question, so I'll mark that as the answer. Thanks. Commented Jun 25 at 6:39
  • Does this answer your question? PHP, pass parameters from command line to a PHP script
    – TylerH
    Commented Jun 25 at 13:25
  • @triplee, I searched and didn't find that, probably because I was looking for something procmail related. I think it's good to have this question posted as well, for someone looking for the same thing. Commented Jun 26 at 18:13

1 Answer 1

0

In PHP, to get the value(s) of parameter(s) passed from the command line, you may parse the $argv

For further details, one may see official documentation

So assuming that your command (to pipe from procmail to the PHP) is:

/usr/bin/php -f /var/www/somefolder/script.php iscron=1 subject=stackoverflow

The script.php can be:

<?php

unset($argv[0]);
parse_str(implode('&',$argv),$_REQUEST);

if ($_REQUEST["iscron"]=="1") {
  // do things for iscron=1
}else{
  // do other things
}

// $_REQUEST["subject"] will be "stackoverflow"

?>
1
  • 1
    thanks. The answer I needed was just the adding of iscron=1 to the pipe command. The parsing example helps too. Commented Jun 25 at 6:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.