Cannot pipe email to php script...

18 posts / 0 new
Last post
#1 Wed, 09/16/2009 - 07:35
ibound

Cannot pipe email to php script...

Hi all,

I can't seem to get this one to work and it is boggling my brain... What I'm trying to so is as the subject says, trying to pipe and email to a php script that is designed to take the email information and process it.

In the email aliases field I have selected the email alias "support" and configured the "Feed to program" setting with "/home/domain.com/public_html/test.php". To test I have created a test.php file that emails me once the script has been executed. So I send an email to support@domain.com and get this in the logs:

"temporary failure. Command output: local: fatal: execvp /home/domain.com/public_html/test.php: Permission denied"

I've tried all manor of permissions variations, but nothing...

When I do a "php -q /home/domain.com/public_html/test.php" , the test script I get the script output and an email in my inbox, so I know the script is working.

Somehow I think php needs to be piped to and the pipe data passed onto the script. Everywhere I look there is no mention of this.

Any help would be much appreciated.

Tim

Wed, 09/16/2009 - 08:36
andreychek

Does it by chance work if you use the same command line that you use when manually running it?

That is, can you use "php -q /home/domain.com/public_html/test.php" in the "Feed to program"?

-Eric

Wed, 09/16/2009 - 09:45
ibound

Thanks or the reply. Tried that and get the output:

"support-domain.com@domain.com (expanded from support@domain.com): Command died with status 1: "php -q /home/domain.com/public_html/test.php". Command output: Could not open input file: /home/domain.com/public_html/test.php"

I'm stumped. Thoughts?

Regards, Tim

Wed, 09/16/2009 - 09:50
andreychek

Okay, just to ask a silly question -- are you super-sure that the path you're using to test.php is correct?

If you run "ls -l home/domain.com/public_html/test.php", does that work and show you info about the file?

-Eric

Wed, 09/16/2009 - 10:33
ibound

Thanks, even silly questions appreciated.

Shows the file info. -rwxrwxrwx permissions and correct user and group...

I would be interested to see if this is working successfully on another Virtualmin server.

I even tried using a shell script... Damn nabbit.

Tim

Wed, 09/16/2009 - 10:43
andreychek

Okay, first thing I'd do is run a "chmod 755" on that script -- I understand you were just troubleshooting, but it definitely doesn't need to be 777, and you don't want random people being able to edit that :-)

Second --

While this shouldn't be an issue, as procmail should be running as your username here -- perhaps we can try this as an experiment.

If you were to make the directories leading up to your script executable, you could rule out an odd permissions issue... something like:

chmod +x /home/domain.com /home/domain.com/public_html

Fri, 07/16/2010 - 11:54 (Reply to #6)
webwzrd

I know this post is getting old, but just wanted to acknowledge that after struggling with getting email piping to work for a whole day, stumbling across this old post and following this suggestion:

chmod +x /home/domain.com /home/domain.com/public_html

...got it working!

Thanks, Brian

Thu, 09/17/2009 - 10:39
ibound

That worked! The main script I'm working with is encoded with sourceguardian and doesn't seem to be doing anything, but my test script took the pipe stdin of the email and emailed the contents to another address, so I know that it's working...

Many thanks for your help Eric!

Cheers, Tim

Mon, 09/21/2009 - 04:59
ibound

One more quick question...

I did a few other tests, only to find that when an email is piped to a file the user and group is set to nobody:nobody... Can that be set per user? Seems a bit odd to me as permissions would need to be very lax if I was to save emails into a users directory...

Thoughts?

Tim

Mon, 09/21/2009 - 09:06
andreychek

Well, the issue you're seeing is fairly a-typical... it sounds like something else may be going awry.

How did you go about installing Virtualmin -- had you used the install.sh script? And what distro are you using?

Lastly, what does this command show:

grep mailbox_command /etc/postfix/main.cf

Mon, 09/21/2009 - 09:48
ibound

Installed via install.sh script on a fresh Centos 5.3 install... Hmmmm..

# grep mailbox_command /etc/postfix/main.cf
# The mailbox_command parameter specifies the optional external
# Unlike other Postfix configuration parameters, the mailbox_command
#mailbox_command = /some/where/procmail
#mailbox_command = /some/where/procmail -a "$EXTENSION"
# has precedence over the mailbox_command, fallback_transport and
mailbox_command = /usr/bin/procmail-wrapper -o -a $DOMAIN -d $LOGNAME

Thanks

Fri, 09/25/2009 - 02:37
ibound

Is anyone else having problems with piping? I've got it working, but it seems hazardous to allow such lax permissions.

Tim

Fri, 01/07/2011 - 21:59
WayneLo

If you are trying to save some time you might consider using a hosted service for the email piping. Another reason this can be helpful is that it handles the email parsing as well. You might checkout (free) http://mailhooks.com or (premium) http://mailnuggets.com to speed things up.

Sun, 12/02/2012 - 15:06
netlan

Command died with status 1: "php -q /home/mydomain/public_html/admin/pipe/pipe.php". Command output: Could not open input file: /home/mydomain/public_html/admin/pipe/pipe.php

Hello, I followed the tips suggested above, but the alias doesn't send or better the pipe.php was not executed, if I run the script in terminal php -q /home/mydomain/public_html/admin/pipe/pipe.php I have Site error: the file xxxx need ioncube loader..bla bla bla Whmcs have been installed by Virtualmin, ioncube is loaded, the file .so is in the folders....

What's up ?

Mon, 12/03/2012 - 07:57
andreychek

Howdy,

You may need to include the path to your PHP config on the command line... something like this:

PHPRC=/home/mydomain/etc/php5 php -q /home/mydomain/public_html/admin/pipe/pipe.php

Otherwise it would default to the system-wide PHP config.

-Eric

Mon, 12/03/2012 - 18:02
netlan

An error comes out when you save the Alias destinations:

"Failed to save alias : '1' is not a valid program or does not exist"

the same error come out if I try to write the command with "|" as 1st character, "| php -q /home/mydomain/public_html/admin/pipe/pipe.php"

PHPRC=/home/mydomain/etc/php5 php -q /home/mydomain/public_html/admin/pipe/pipe.php

is wrote right ? Or Virtualmin doesn't accept the string because want it write differently , or for what ?? The pipe setting is for the Whmcs Ticket System

Eric need again your touch !

Mon, 12/03/2012 - 22:10
andreychek

To use a pipe, you'd want to go into the "Advanced mode" tab when creating the alias. Then, select "Feed to Program" in the dropdown.

Using that option should allow you to pipe to your script.

-Eric

Tue, 12/04/2012 - 04:24
netlan

in "Feed to Program" I have the error, as I told you, I have simply modified the string adding the custom php, adding "PHPRC=/home/mydomain/etc/php5" cause the error, if I write only "php -q /home/mydomain/public_html/admin/pipe/pipe.php" that string is accepted, but not well executed, the email sender receive an error from the mail server "Command output: Could not open input file: /home/mydomain/public_html/admin/pipe/pipe.php" I have tried to add in the main php.ini the reference to ioncube, but I receive an ioncube error when I execute the script. If I try to run in terminal, "PHPRC=/home/mydomain/etc/php5 php -q /home/mydomain/public_html/admin/pipe/pipe.php", I receive this error:

PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mcrypt.so' - /usr/lib64/php/modules/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0

Topic locked