1

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.

2
  • Is there a reason you don't have permission to the script?
    – Tablemaker
    Nov 21, 2011 at 22:33
  • yes it's a shared script between multiple users that only the admin can edit
    – User
    Nov 21, 2011 at 22:51

3 Answers 3

3

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.

1

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.

1

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.

3
  • ok, that is a step toward the solution, but how do I get the sender address?
    – User
    Nov 21, 2011 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. Nov 21, 2011 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, 2011 at 23:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .