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 Problems

Discussion in 'E-mail Discussions' started by doni49, Feb 17, 2007.

  1. doni49

    doni49 Well-Known Member

    Joined:
    Oct 4, 2006
    Messages:
    74
    Likes Received:
    0
    Trophy Points:
    6
    Hello all!

    I'm trying to pipe email to a PHP script (I've read the thread at the following link http://forums.cpanel.net/showthread.php?t=50985).

    In the beginning, I wasn't even getting an error message. NOTHING happened. I tried commenting out the function (and the call to it) and ran it at the command line. I got an error message that the command "myscript.php" could not be found. So I entered "/usr/local/bin/php myscript.php" (I had cd'd to the file's location) and got NO error message. STILL no email message. So I go back to CPanel and enter the full path to PHP after the pipe and the script name (with the full path). I eventually DO get a return email message telling me that the recipient could not be verified (this is WITH the function and the call to it uncommented).

    PHP's mail function DOES work for me--my contact page uses it and I just recieved a msg via that page today.

    Permissions for the file are set at 777 currently.

    Server info (copy/pasted from cpanel):
    PHP:
    <?php
        
    #!/usr/local/bin -q
        
    $msg "You Said:  \r\n";
        function 
    mailRead($iKlimit ""){
            
    // Purpose:
            //   Reads piped mail from STDIN
            //
            // Arguements:
            //   $iKlimit (integer, ptional): specifies after how many kilobytes reading of mail should stop
            //   Defaults to 1024k if no value is specified
            //     A value of -1 will cause reading to continue until the entire message has been read
            //
            // Return value:
            //   A string containing the entire email, headers, body and all.

            // Variable perparation
                // Set default limit of 1024k if no limit has been specified
                
    if ($iKlimit == "") {
                    
    $iKlimit 1024;
                }

                
    // Error strings
                
    $sErrorSTDINFail "Error - failed to read mail from STDIN!";

            
    // Attempt to connect to STDIN
            
    $fp fopen("php://stdin""r");

            
    // Failed to connect to STDIN? (shouldn't really happen)
            
    if (!$fp) {
                echo 
    $sErrorSTDINFail;
                exit();
            }

            
    // Create empty string for storing message
            
    $sEmail "";

            
    // Read message up until limit (if any)
            
    if ($iKlimit == -1) {
                while (!
    feof($fp)) {
                    
    $sEmail .= fread($fp1024);
                }
            } else {
                while (!
    feof($fp) && $i_limit $iKlimit) {
                    
    $sEmail .= fread($fp1024);
                    
    $i_limit++;
                }
            }

            
    // Close connection to STDIN
            
    fclose($fp);

            
    // Return message
            
    return $sEmail;
        }
        
    $msg2 mailRead();

        
    $headers "From:  Pipe Test<myaddress@mydomain.com>\r\n";
        
    mail("myaddress@mydomain.com""PHP Pipe Test"$msg$headers);
    ?>
     
  2. doni49

    doni49 Well-Known Member

    Joined:
    Oct 4, 2006
    Messages:
    74
    Likes Received:
    0
    Trophy Points:
    6
    Never Mind

    Never mind. I don't know what change worked, but it's working now.

    Thanks anyway.
     
Loading...

Share This Page