简体   繁体   中英

Procmail and PHP script

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.*invoice@domain.it
! Rechnung@domain.it

:0
* ^To.*invoice@domain.it
| munpack -q -C $ATTACHinvoice

:0c
* ^From:.*selva
! info@domain.it

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

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

:0
* ^To.*selva@domain.it
| /usr/bin/php /home/www/cron/mail_selva.php

:0 w
! hannes@domain.it

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.

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
  ! info@domain.it

  :0c
  | munpack -q -C $ATTACHselva

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

Then you're still stuck with the ^To.*selva@domain.it with an identical delivery action. Maybe things could still be refactored.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM