jamminjames
jamminjames

Reputation: 67

Using procmail to pipe to a php script, can I add a variable to be checked

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.

Upvotes: 0

Views: 77

Answers (1)

Ken Lee
Ken Lee

Reputation: 8043

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"

?>

Upvotes: 0

Related Questions