Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Pipe and forward

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

  1. mayaboys

    mayaboys Member

    Jan 22, 2009
    Likes Received:
    Trophy Points:
    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:

    In my file PHP I added well the path in first line for the php and put this file in chmod 644:

    #!/usr/local/bin/php -q
    // 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);
    // 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([email protected]_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:

    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 [email protected]
    The following text was generated during the delivery attempt:
    ------ pipe to |/home/user/pipe.php
          generated by [email protected] ------
    ------ 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

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice