Jump to content

procmail: Piping to a PHP script.


eon

Recommended Posts

Hello.

 

I have my .procmailrc file set up to pipe mail to a simple php script I've written.  The only thing the script does at this point is echo back a "hello" message.  However, procmail does not execute the script properly.

 

Here's my script (/home/webs/site.com/scripts/echo.php):

 

#!/usr/local/bin/php
<?php
echo "hi.";
?>

 

When I execute this script from the shell, it performs as expected.  A message is echoed to the terminal ("hi.") and the script quits.

 

Here is my .procmailrc:

 

LOGFILE=/var/log/procmail.log
VERBOSE=YES
:0
| /home/webs/site.com/scripts/echo.php

 

And here is what is logged by procmail:

 

 

procmail: [11765] Fri Aug  6 16:12:48 2010
procmail: Executing "/home/webs/site.com/scripts/echo.php"
procmail: [11765] Fri Aug  6 16:12:48 2010
procmail: Assigning "LASTFOLDER=/home/webs/site.com/scripts/echo.php"
procmail: Notified comsat: "root@:/home/webs/site.com/scripts/echo.php"
From fodii2160@quicknet.nl  Fri Aug  6 16:12:48 2010
Subject: Heard of the fellowship?
  Folder: /home/webs/site.com/scripts/echo.php                     728
/home/webs/site.com/scripts/echo.php: line 2: ?php: No such file or directory
/home/webs/site.com/scripts/echo.php: line 4: syntax error near unexpected token `newline'
/home/webs/site.com/scripts/echo.php: line 4: `?>'
procmail: [11769] Fri Aug  6 16:13:00 2010
procmail: Executing "/home/webs/site.com/scripts/echo.php"
/home/webs/site.com/scripts/echo.php: line 2: ?php: No such file or directory
/home/webs/site.com/scripts/echo.php: line 4: syntax error near unexpected token `newline'
/home/webs/site.com/scripts/echo.php: line 4: `?>'
procmail: [11769] Fri Aug  6 16:13:00 2010
procmail: Error while writing to "/home/webs/site.com/scripts/echo.php"
procmail: Assigning "LASTFOLDER=/home/webs/site.com/scripts/echo.php"
procmail: Locking "/var/mail/root.lock"
procmail: Assigning "LASTFOLDER=/var/mail/root"
procmail: Opening "/var/mail/root"
procmail: Acquiring kernel-lock
procmail: Unlocking "/var/mail/root.lock"
procmail: Notified comsat: "root@1356229:/var/mail/root"
From mudepeli7695@rr.com  Fri Aug  6 16:13:00 2010
Subject: Intense - the secret
  Folder: /var/mail/root      

 

It appears that when procmail runs the script, the "#!/usr/local/bin/php" isn't recognized, so it's being run as if it's a shell script instead of using the php interpreter.  This would explain errors such as "line 2: ?php: No such file or directory".  (If you just run a php script from the command line without the path to the interpreter, that's exactly the kind of error you'll get).

 

I've tried modifying my .procmailrc file like so:

 

:0

| /usr/local/bin/php /home/webs/site.com/scripts/echo.php

 

(I removed the path to the interpreter from the script itself when running as above.)  No joy.  I'm at my wit's end here. 

 

If the script were being executed properly, I would see the "hi." message being echoed back in procmail.log instead of the execution errors.

 

Help?

Link to comment
Share on other sites

For anyone who is curious, I fixed my problem by routing via a sendmail .forward file instead of through procmail.

 

I was actually working with a PHP script that routes mail to a MySQL database.  That script wasn't working when I piped through procmail, but as soon as I used the .forward file instead, it worked great.

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.