The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Email piping to a php script fopen disabled

Discussion in 'cPanel Developers' started by broncha, Apr 19, 2010.

  1. broncha

    broncha Active Member

    Joined:
    Feb 3, 2009
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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:
    root@host [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 someuser@domain.com
       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.
     
  2. leefrom

    leefrom Active Member

    Joined:
    May 27, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    Is the script executable on your filesystem?
     
  3. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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
     
  4. broncha

    broncha Active Member

    Joined:
    Feb 3, 2009
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Kathmandu,Nepal
    cPanel Access Level:
    Root Administrator
    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 152207@domain.com
    
    The following text was generated during the delivery attempt:
    
    ------ pipe to |/path /to/read.sh
          generated by 152207@domain.com ------
    
    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.
     
  5. broncha

    broncha Active Member

    Joined:
    Feb 3, 2009
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Kathmandu,Nepal
    cPanel Access Level:
    Root Administrator
    Hi,

    Got it resolved.
    The problem was with the creation of the mail.txt
    It didn't exist and the creation of the file was forbidden.
    I created a mail.txt file and chmod it to 777.

    The script is working now.

    Thanks . :)
     
  6. goldy_rocky

    goldy_rocky Member

    Joined:
    Jul 16, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Thanks a ton for this.

    Worked like charm
     
Loading...

Share This Page