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.

Pipe and forward

Discussion in 'E-mail Discussions' started by mayaboys, May 28, 2010.

  1. mayaboys

    mayaboys Member

    Joined:
    Jan 22, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Hello with all,

    I wish to recover my email via PHP for a support, I have thus to create a redirection via my file php with a pipe:

    HTML:
    |/home/user/pipe.php
    In my file PHP I added well the path in first line for the php and put this file in chmod 644:

    Code:
    #!/usr/local/bin/php -q
    <?php
    // Config
    $dbuser = '';
    $dbpass = '';
    $dbname = '';
    $dbhost = 'localhost';
    $email = ''; // an email address required in case of errors
    
    // read from stdin
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd)) {
        $email .= fread($fd, 1024);
    }
    fclose($fd);
    // handle email
    $lines = explode("\n", $email);
    
    // empty vars
    $from = "";
    $subject = "";
    $headers = "";
    $message = "";
    $splittingheaders = true;
    for ($i=0; $i < count($lines); $i++) {
        if ($splittingheaders) {
            // this is a header
            $headers .= $lines[$i]."\n";
    
            // look out for special headers
            if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
                $subject = $matches[1];
            }
            if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
                $from = $matches[1];
            }
            if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
                $to = $matches[1];
            }
        } else {
            // not a header, but message
            $message .= $lines[$i]."\n";
        }
    
        if (trim($lines[$i])=="") {
            // empty line, header section has ended
            $splittingheaders = false;
        }
    }
    
    if ($conn = @mysql_connect($dbhost,$dbuser,$dbpass)) {
      if(!@mysql_select_db($dbname,$conn))
        mail($email,'Email Logger Error',"There was an error selecting the email logger database.\n\n".mysql_error());
      $from    = mysql_real_escape_string($from);
      $to    = mysql_real_escape_string($to);
      $subject = mysql_real_escape_string($subject);
      $headers = mysql_real_escape_string($headers);
      $message = mysql_real_escape_string($message);
      $email   = mysql_real_escape_string($email);
      $result = @mysql_query("INSERT INTO email_log (`to`,`from`,`subject`,`headers`,`message`,`source`) VALUES('$to','$from','$subject','$headers','$message','$email')");
      if (mysql_affected_rows() == 0)
        mail($email,'Email Logger Error',"There was an error inserting into the email logger database.\n\n".mysql_error());
    } else {
      mail($email,'Email Logger Error',"There was an error connecting the email logger database.\n\n".mysql_error());
    }
    ?>
    
    When I send the email on the address my script recovers my email well and sends it towards Mysql aucunes errors in the logs but however I always receive an Email Delivery System without description of error:

    HTML:
    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 |/home/user/pipe.php
       generated by support@xxxx.com
    
    The following text was generated during the delivery attempt:
    
    ------ pipe to |/home/user/pipe.php
          generated by support@xxxx.com ------
    
    
    
    ------ This is a copy of the message, including all the headers. ------
    Thus approximately the system functions except that to each time one sends an email one receives an email Mail Delivery System in return!

    it seems to me that the problem comes from code PHP because when I leave just the preimére line #! /usr/local/bin/php - Q that I function is not email of error but when I indicate an end of code php that does not go even any more a “echo”

    Thank you with all for your answer
     
Loading...

Share This Page