Email piping to a php script fopen disabled

broncha

Active Member
Feb 3, 2009
32
0
56
Kathmandu,Nepal
cPanel Access Level
Root Administrator
Hi,

I was trying to pipe emails to a php script. The script is working fine as I can simulate the piping from the shell:

here is read.sh

Code:
#!/usr/bin/php -q
<?php
/* Read the message from STDIN */
$fd = fopen("php://stdin", "r");
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
/* Saves the data into a file */
$fdw = fopen("mail.txt", "w+");
fwrite($fdw, $email);
fclose($fdw);
/* Script End */
Code:
[email protected] [public_html/broncha]# ./read.sh << EOM
> this is a test mail
> EOM
When i execute the script like this It works perfectly fine.But when I send email , it bounces back with following error:

Code:
This message was created automatically by mail delivery software.

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 |/path/to/read.php
   generated by [email protected]
   local delivery failed
What can be the issue? Please help

Edit:
Sorry the fopen in the thread title has got nothing to do with this. I was getting that error earlier which I have got fixed.
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
hmm, maybe this is too simply but the error message is "path/to/read.php" not read.sh. I understand you probably changed the path for posting, but thought I'd mention it...

like Lee said, I'l also check the permissions/owner of the script so that it can be used by the invoking script.

Regards,
-Dave
 

broncha

Active Member
Feb 3, 2009
32
0
56
Kathmandu,Nepal
cPanel Access Level
Root Administrator
hmm, maybe this is too simply but the error message is "path/to/read.php" not read.sh. I understand you probably changed the path for posting, but thought I'd mention it...

like Lee said, I'l also check the permissions/owner of the script so that it can be used by the invoking script.

Regards,
-Dave
oops some silly mistakes there.
The server I was trying the script on had some problems problems so php was throwing out errors so the mail were being rejected.

I moved the script to another server.Now I get the fopen problem back.
the bounced message says:
Code:
This message was created automatically by mail delivery software.

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 |/path /to/read.sh
   generated by [email protected]

The following text was generated during the delivery attempt:

------ pipe to |/path /to/read.sh
      generated by [email protected] ------

PHP Warning:  fopen(mail.txt) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in /path /to/read.sh on line 11
<br />
<b>Warning</b>:  fopen(mail.txt) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/path /to/read.sh</b> on line <b>11</b><br />
PHP Warning:  fwrite(): supplied argument is not a valid stream resource in /path /to/read.sh on line 12
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in <b>/path /to/read.sh</b> on line <b>12</b><br />
PHP Warning:  fclose(): supplied argument is not a valid stream resource in /path /to/read.sh on line 13
<br />
<b>Warning</b>:  fclose(): supplied argument is not a valid stream resource in <b>/path /to/read.sh</b> on line <b>13</b><br />
So, I am pretty much sure this is about PHP.
but running the script from shell works fine.
fopen() is disabled when an email is piped into it.

Any suggestions, how I configure PHP for this?

Thanks.