Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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

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

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

Your Answer

 
discard

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.