Procmail and PHP script

816 views Asked by At

I am using postfix and procmail. But I have a problem with procmail and php. The php-code /home/www/cron/mail_visirun.php run without any problem, but if /home/www/cron/mail_selva.php shoud be run on the logfile comes an error message:

My procmail file:

My php file /home/www/cron/mail_selva.php:

LOGFILE=/var/log/procmailrc.log
VERBOSE=yes
ATTACHinvoice=`echo /home/dok/dispo/RGein`
ATTACHselva=`echo /home/dok/dispo/Selva`
:0
* ^From:.*visirun
| /usr/bin/php /home/www/cron/mail_visirun.php

:0c
* ^To.*[email protected]
! [email protected]

:0
* ^To.*[email protected]
| munpack -q -C $ATTACHinvoice

:0c
* ^From:.*selva
! [email protected]

:0c
* ^From:.*selva
| munpack -q -C $ATTACHselva

:0
* ^From:.*selva
| /usr/bin/php /home/www/cron/mail_selva.php

:0
* ^To.*[email protected]
| /usr/bin/php /home/www/cron/mail_selva.php

:0 w
! [email protected]

The php file /home/www/cron/mail_selva.php:

<?php
echo "OK";
?>

My logile:

procmail: Executing "/usr/bin/php,/home/www/cron/mail_selva.php"
procmail: Error while writing to "/usr/bin/php"
procmail: Assigning "LASTFOLDER=/usr/bin/php /home/www/cron/mail_selva.php"

I can not understand why one script run and another script give an error.

1

There are 1 answers

0
tripleee On

The error is that your PHP script fails to read its standard input. Procmail detects this, and regards the delivery as unsuccessful.

If the plan is for the script to do something useful with its standard input, just do that, and the error will go away.

If not, maybe explain in more detail (probably in a new question by now) what your script does and what you hope should happen when Procmail pipes the current message into it.


Stylistic remarks:

  • You want to get rid of the crazy Useless Use of echo in backticks. Change variable=`echo value` to variable='value' (possibly without the quotes, if the value does not require quoting).
  • The w flag on the final recipe is weird. I'm not sure what you could expect that to do. What is your intention?
  • The repeated conditions are not an error, but slightly problematic. I would refactor so that you only have one regex to update if you ever should need to.
:0
* ^From:.*selva
{
  :0c
  ! [email protected]

  :0c
  | munpack -q -C $ATTACHselva

  :0
  | /usr/bin/php /home/www/cron/mail_selva.php
}

Then you're still stuck with the ^To.*[email protected] with an identical delivery action. Maybe things could still be refactored.