Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Member broncha's Avatar
    Join Date
    Feb 2009
    Location
    Kathmandu,Nepal
    Posts
    32
    cPanel/Enkompass Access Level

    Root Administrator

    Default Email piping to a php script fopen disabled

    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.
    ========================================
    http://www.rajesharma.com
    http://www.twitter.com/broncha

  2. #2
    Member
    Join Date
    May 2008
    Posts
    30

    Default

    Is the script executable on your filesystem?

  3. #3
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default

    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
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  4. #4
    Member broncha's Avatar
    Join Date
    Feb 2009
    Location
    Kathmandu,Nepal
    Posts
    32
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by cPanelDavidN View Post
    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 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.
    ========================================
    http://www.rajesharma.com
    http://www.twitter.com/broncha

  5. #5
    Member broncha's Avatar
    Join Date
    Feb 2009
    Location
    Kathmandu,Nepal
    Posts
    32
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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 .
    ========================================
    http://www.rajesharma.com
    http://www.twitter.com/broncha

  6. #6
    Member
    Join Date
    Jul 2007
    Posts
    5

    Default Re: Email piping to a php script fopen disabled

    Thanks a ton for this.

    Worked like charm

Similar Threads & Tags
Similar threads

  1. Email Piping to script works, but sender gets an error message?
    By itzhero in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 11-24-2010, 12:50 PM
  2. Piping email to script question.
    By SosyMe in forum E-mail Discussions
    Replies: 1
    Last Post: 06-08-2010, 08:57 PM
  3. Pass a variable to PHP Script when piping msg to that script?
    By doni49 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 03-02-2007, 06:52 PM
  4. Mail piping problem with PHP script - Help please
    By Mar in forum cPanel and WHM Discussions
    Replies: 12
    Last Post: 04-27-2004, 03:52 PM
  5. Replies: 1
    Last Post: 06-20-2003, 01:57 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube