Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've configured an email address to pipe (forward) all emails to /path/to/script.php

I thought I'll receive the output of the script as an email reply but it doesn't work.

How can I get the output of the script and send a reply email with the output as the email content?

(*) I know I can use mail() inside the script but I don't have permissions to edit the script, and I can't copy the script because it's being updated from time to time.

share|improve this question
Is there a reason you don't have permission to the script? – TylerShads Nov 21 '11 at 22:33
yes it's a shared script between multiple users that only the admin can edit – User Nov 21 '11 at 22:51
up vote 3 down vote accepted

You could just add another pipe and tee the raw mail into a temporary file, then pipe to the mentioned read-only script, lastly pipe to another php script to do the rest.

The last php script will read the output from the read-only script and the sender address from the temporary file, then send the mail using mail() php function.

| tee /path/to/tmp/file | /path/to/script.php | /path/to/another.php

BTW, I've never used such an approach neither I know if it's possible but it does look that Can's answer could work out with command-line macros, it's a nicer solution so if it does work please reply here and tell us how.

share|improve this answer

I am sorry, but unless the script is design to correctly operate, it isn't going to know how to just automatically reply back just because you are piping data do it.

If you can't change the script, perhaps you need to write another front-end script that captures the output and does what you require.

share|improve this answer

You could modify your mailing configuration. It should be along the lines of

<run your php file with arguments> | sendmail <arguments>

Hard to be specific without knowing your configuration.

share|improve this answer
ok, that is a step toward the solution, but how do I get the sender address? – User Nov 21 '11 at 22:52
if you have access to the incoming mail headers, you can use a combination of grep, cut commands to extract the sender address. – Can Kavaklıoğlu Nov 21 '11 at 22:57
I need to write it in the pipe command in order to use your solution, I don't know if it's possible to access the headers... – User Nov 21 '11 at 23:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.