DreamHost Web Hosting
Discussion Forum


Forums
   >> Programming
*Threaded Mode

Subject Email to PHP via Procmail  
Posted bybuhlenbrock (DH New User )
Posted on07/26/04 05:37 AM



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 http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914 but not having much luck.

i have set up a filter through procmail
:0
* ^TO_my@email.com
| $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.

thanks!




Subject Re: Email to PHP via Procmail new [re: buhlenbrock]  
Posted bywillAdministrator (DH Pooh-Bah)
Posted on07/26/04 12:22 PM



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?



Subject Re: Email to PHP via Procmail new [re: will]  
Posted bybuhlenbrock (DH New User )
Posted on07/27/04 06:33 PM



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:

DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir
PMDIR=$HOME/.procmail
SHELL=/bin/sh
VERBOSE=yes
LOGFILE=$HOME/logfile

:0
* ^TO_the@email\.com
|/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_.])?)the@email\.com"
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 my@email.com Tue Jul 27 18:31:35 2004
Subject:
Folder: /usr/local/bin/php /my/ 989
/usr/local/bin/php: /usr/local/bin/php: No such file or directory



Subject Re: Email to PHP via Procmail new [re: buhlenbrock]  
Posted bywillAdministrator (DH Pooh-Bah)
Posted on07/27/04 08:27 PM



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



Subject Re: Email to PHP via Procmail new [re: will]  
Posted bybuhlenbrock (DH New User )
Posted on07/28/04 01:59 PM



will,

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.



Subject Re: Email to PHP via Procmail new [re: buhlenbrock]  
Posted bybuhlenbrock (DH New User )
Posted on07/29/04 05:16 AM



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?

thanks!



Subject Re: Email to PHP via Procmail new [re: buhlenbrock]  
Posted byHuns (DH New User )
Posted on08/08/04 06:05 AM



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:
----------------------------------------------------------
DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir
PMDIR=$HOME/.procmail
SHELL=/bin/sh
VERBOSE=yes
LOGFILE=$HOME/logfile
LD_LIBRARY_PATH=$HOME/email/php
PHP=$HOME/email/php/php

:0
* ^TO_youraddress@yoursite\.net
|$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 http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914 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!



Subject Re: Email to PHP via Procmail new [re: Huns]  
Posted bybuhlenbrock (DH New User )
Posted on08/26/04 02:08 PM



huns,

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 user@server.dreamhost.com. 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?



Subject Re: Email to PHP via Procmail new [re: buhlenbrock]  
Posted bynateModerator (DH Regular)
Posted on08/27/04 09:36 AM



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

http://www.zend.com/manual/function.mail.php


nate.



Subject Re: Email to PHP via Procmail new [re: nate]  
Posted bybuhlenbrock (DH New User )
Posted on08/30/04 11:02 AM



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....

thoughts?



Subject Re: Email to PHP via Procmail new [re: buhlenbrock]  
Posted bywillAdministrator (DH Pooh-Bah)
Posted on08/30/04 11:24 AM



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.


Subject Re: Email to PHP via Procmail new [re: will]  
Posted bybuhlenbrock (DH New User )
Posted on08/31/04 12:14 PM



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



Subject Re: Email to PHP via Procmail new [re: Huns]  
Posted bydelden (DH New User )
Posted on09/01/04 07:28 AM



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

Robert



Subject Re: Email to PHP via Procmail new [re: delden]  
Posted bywillAdministrator (DH Pooh-Bah)
Posted on09/01/04 08:50 AM



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 (').



Subject Re: Email to PHP via Procmail new [re: will]  
Posted bydelden (DH New User )
Posted on09/01/04 01:19 PM



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.

Robert



Subject Re: Email to PHP via Procmail new [re: Huns]  
Posted byblueorder (DH New User )
Posted on01/24/05 06:46 PM



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?

Thanks

blueorder


Subject Re: Email to PHP via Procmail new [re: blueorder]  
Posted bysobriquet (DH New User )
Posted on06/18/05 09:10 AM



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

I'm having the same problem!!!



Subject Re: Email to PHP via Procmail new [re: sobriquet]  
Posted byCiao121 (DH New User )
Posted on11/22/05 12:48 PM



Same error... any help? :)




*Threaded Mode
Jump to