Email to PHP via Procmail

I have done gratuitous searching on the web on this topic and have found very little resolution. I even saw a few posts on this forum, but not answers.

i am following this tutorial but not having much luck.

i have set up a filter through procmail

  • ^
    | $HOME/my/script.php

i saw in a previous post that a reason this is erroring out is b/c php is not installed on all of the mail servers. i saw one suggestion to copy the php binary into a folder in my share…but it still needed other libraries.

i would really like some help here as i’m over a week into this process and can’t seem to get anywhere.


It should be installed.
Does it work if you do:
|/usr/local/bin/php $HOME/my/script.php ?

What is the exact error you’re seeing in your procmail log?

that still didn’t seem to work. alternatively, i am open to trying this with a .forward file, but i’ve had more luck so far with procmail.

for more detail here is my exact .procmailrc file:



  • ^
    |/usr/local/bin/php $HOME/my/script.php

and here is the resulting error message:

procmail: Match on "(^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope|Apparently(-Resent)?)-To):(.*[^-a-zA-Z0-9_.])?)"
procmail: Assigning "LASTFOLDER=/usr/local/bin/php /my/script.php"
procmail: Executing "/usr/local/bin/php,/my/script.php"
procmail: Notified comsat: "username@:/usr/local/bin/php /my/script.php"
From Tue Jul 27 18:31:35 2004
Folder: /usr/local/bin/php /my/ 989
/usr/local/bin/php: /usr/local/bin/php: No such file or directory

Open a support request, and have them verify that php is installed on all mail machines for your cluster.


i just got a message from ralph stating that you are correct and php is not installed on any of the mail servers in my cluster. i’m really hoping this won’t be a problem to get get accomplished.

thanks for your help thus far.

okay, so ralph informed me that they WON’T install php on my cluster. can i be moved to a cluster with php?

he suggested using cron, but i need a real-time solution. it really shouldn’t be this complicated.

what are my options?
install php in my home directory?
get someone to show me how to do the same thing in perl?
move to another hosting provider?


I wanted to do this myself, and I just succeeded, so here’s how to do it.

Make a directory, say $HOME/email/php. (An empty directory, you don’t want to use a directory you have another PHP binary in or anything wierd like that.) Change to this directory and run the following:
cp /usr/local/bin/php .
for i in ldd php |awk '{print $3}'; do cp $i .; done

This will place a copy of the PHP binary in the directory, AND all the libraries that it depends on (which are not the same on the mail machines.)

Next, change to your home directory and make sure you have a file called .forward.postfix which contains this single line, including the quotes:
"|/usr/bin/procmail -t"

Now, still in your home directory, create your .procmailrc file:



  • ^
    |$PHP $HOME/email/email.php

Notice the LD_LIBRARY_PATH environment variable. This will force the PHP binary to search in the specified directory for any dynamic libraries that it needs to load. This is how we get the PHP binary to use the library files it actually works with, rather than trying to use the ones on the mail server (which doesn’t have all the libraries it needs.)

Now, in your ~/email/ directory, create a .php file to process incoming email. I found the one at works perfectly. All this does is read the incoming mail over stdin and parse it for headers, subject, and body. After that you can do whatever you want with it.

After you get everything up and running, you may want to comment out (put a # in front of) the VERBOSE and LOGFILE variables in .procmailrc.

Good luck!


thanks a bunch…i plan to try that out when i get a chance. for now, i do have it working with chron.

but here’s another problem i’ve run into.

the result of my script emails a reply back to the incoming email, but no matter what i try the return-path shows up as i have added the desired address in the PHP mail() headers (reply-to, return-path, from) and included X-Mailer.

is there any way for the return-path to be an address of my choosing?

See this manual entry about how to set the envelope sender:


thanks nate.

i read over the site you sent, but it doesn’t seem to address my problem. when i check the headers of an email my script sends out, it has replaced my “return-path” with the user@server address i don’t want made visible. normally, this wouldn’t be a problem as the “from” and reply-to" addresses are correct…BUT this is being sent to a cell phone and the “return-path” is the only email address it displays…


Yes it does address your problem.

Set the envelope-sender to the correct address, and you’ll see [assuming the script uses PHP’s mail() function]. Otherwise you may need to adjust the call to sendmail by hand.

sorry, my bad. after reading it three times through i finally found the relevant bit! i never said i was smart.

Huns, I saw your post regarding setting up an empty directory and adding a php binary to it.

I encountered a problem with the second line:
cp /usr/local/bin/php .
for i in ldd php |awk '{print $3}'; do cp $i .; done

did I miss some of the ‘quotes’ ? Is there another way to copy all the dependable libraries?

Hoping for a response, thanks


Are you cut and pasting that? The first and last things that look like quotes are backticks (`); the ones around {print $3} are single quotes (’).

Thanks, this helped.
However I now get “missing destination file” when using this command.

I am not very good at this stuff, so apologies for the basic and naive question.


I’ve been trying to do this following your instructions Huns but when trying to forward the email to php I get the following error in the logs…

Error while writing to “/home/[user]/[dir]/php/php”

Any suggestions?



Did you ever sort out the "Error while writing to… " error?

I’m having the same problem!!!

Same error… any help? :slight_smile: