6

This may be a ridiculous question, but it's been bothering me for a while. I have a mail forwarder piped to a PHP script, it receives perfectly, however I have the following error mailed back to me instantly:

A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

  pipe to |/home/[webroot]/public_html/external/mobile/email.php
    generated by mobile@[mydomain]

The following text was generated during the delivery attempt:

X-Powered-By: PHP/5.2.13 
Content-type: text/html

As you can see, Exim thinks the header response an error from the script I have. The script can receive the Email perfectly from php://stdin but Exim is quick-replying with the error.

Plus,

  • It's running from console, not Apache so HTAccess or configuring Apache most likely would do nothing.
  • I can not find any solution, or anyone with the same problem.

So my question is: How to I get rid of those two headers?

Thanks, ~Jonny

Edit, Source:

    #!/usr/bin/php
<?php
    $fd = fopen("php://stdin", "r");
        $email = "";
        while (!feof($fd)) {
         $email .= fread($fd, 1024);
        }
        fclose($fd);

        $dat = fopen(dirname(__FILE__).'/test.txt', 'w');
        fwrite($dat, $email);
        fclose($dat);
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
JonnyLitt
  • 763
  • 6
  • 11

2 Answers2

16

looks like you're running php-cgi while you need php-cli (just "php"). Run php -v to make sure. If cgi is the case, try "-q" option.

user187291
  • 53,363
  • 19
  • 95
  • 127
  • As far as I tried with php -v it spammed back "Content-type: text/html", I went ahead and tried running it with the -q option and it still returned the headers. Exim is still being rather touchy with it. – JonnyLitt Mar 14 '10 at 20:55
  • 1
    try adding header('Content-type: '); to the top of your script. Also checkout http://www.php.net/manual/en/function.header-remove.php – Jimmy Ruska Mar 14 '10 at 21:06
  • eep, Did that, the problem is: I don't have PHP <= 5.3.0 (Needed for Header_remove), rather version 5.2.4. I can't update either because I am on a shared host and they've argued against it being paranoid about bugs in the newer PHP versions. – JonnyLitt Mar 14 '10 at 21:19
  • Didn't get it - what exactly does "php -v" say? – user187291 Mar 14 '10 at 21:56
  • PHP 5.2.13 (cli) (built: Mar 3 2010 11:22:08) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies with the ionCube PHP Loader v3.3.10, Copyright (c) 2002-2009, by ionCube Ltd., and with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies – JonnyLitt Mar 14 '10 at 22:04
  • 2
    Aha! I hashbang'd the wrong PHP. I changed it to #!/usr/bin/php5 rather than #!/usr/bin/php and the errors have stopped. – JonnyLitt Mar 14 '10 at 22:06
  • Haha, simple change by adding the 5, who knew xD. Thanks mate. – JonnyLitt Mar 14 '10 at 22:21
  • 1
    @JonnyLitt You should repost your "changed it to #!/usr/bin/php5" comment as another answer. You can answer your own questions, and that will be much easier for other people to find than searching through the comments of an answer that didn't work. Also you might get upvotes and reputation points :-) – rjmunro Oct 16 '12 at 09:13
1

Had the same issue. My hosts told me I could use php-5.4-cli (normally I used php-5.4).

Adding -cli worked for me.

gelviis
  • 448
  • 1
  • 4
  • 19