I have a procmail recipe that takes the body of a mail and sends it to a php script. However, procmail complains with an error.

Here is how it works: The user that needs access to hardware parameters has to register via e-mail like this:

Procmail then sends the body off to the php script to be processed. The reason I use "??" is to make it easier for me to filter out the garbage of what comes with the body via grep.

Here is the error in procmail.log:

From fetchmail  Fri Nov 25 15:41:36 2016
Subject: Register
Folder: /root/mail/inbox/inbox                     3673
procmail: [20601] Fri Nov 25 15:43:44 2016
procmail: Assigning "DEFAULT=/root/mail/inbox/inbox"
procmail: Assigning "PMDIR=/root/.procmail"
procmail: Match on "^Subject.*[R|r]egister$"
procmail: Executing "/usr/bin/php,-f,/root/data/scripts/register.php"
procmail: Executing "??myusername:me@gmail.com:mypass1??"
/bin/sh: 0: Can't open ??myusername:me@gmail.com:mypass1??

Here is my procmail recipe:

* ^Subject.*[R|r]egister$
  :0 bf
  | `/usr/bin/php -f /root/data/scripts/register.php`

Here is an abbreviated snippet of the register.php script:

while ( false !== ( $user_register = fgets ( STDIN ) ) )
  $user_info = preg_match ( "/\?\?.*\?\?/", @$user_register, $new_registration ) ;
  foreach ( $new_registration as $input )
    print ( $input."\n" ) ;

I do not think it has anything to do with the php code as I have similarly structured recipes and php code.

Any pointers?

  • Remove the backquotes `` from around your php line in the recipe.
    – meuh
    Nov 25 '16 at 18:00

The correct syntax is to remove the backquotes around the PHP script, unless its specific purpose is to print the name of the command you want to pipe the message to on its standard output.

In other words,

echo "moo" | `echo wc`

is equivalent to

echo "moo" | wc

There's a number of other simplifications and corrections you can make. Procmail conditions are case-insensitive by default (and I don't think you intend to match |egister though your current code does) and there is no need to use braces just to add some flags.

* ^Subject.*register$
| /usr/bin/php -f /root/data/scripts/register.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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