eon Posted August 6, 2010 Share Posted August 6, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/210018-procmail-piping-to-a-php-script/ Share on other sites More sharing options...
steviewdr Posted August 7, 2010 Share Posted August 7, 2010 Make sure the top of your php file is like: #!/usr/bin/env php <?php echo "hi"; ?> -steve Quote Link to comment https://forums.phpfreaks.com/topic/210018-procmail-piping-to-a-php-script/#findComment-1096411 Share on other sites More sharing options...
eon Posted August 7, 2010 Author Share Posted August 7, 2010 Steve: I have the full path to my php binary at the top of the script, as shown in my original post. Thanks for the reply. Quote Link to comment https://forums.phpfreaks.com/topic/210018-procmail-piping-to-a-php-script/#findComment-1096431 Share on other sites More sharing options...
eon Posted August 8, 2010 Author Share Posted August 8, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/210018-procmail-piping-to-a-php-script/#findComment-1096486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.