problem using PHP script to filter piped emails

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dr. Jones
    Junior Member
    • Apr 2007
    • 11

    #1

    problem using PHP script to filter piped emails

    I have my public e-mail address pipe to a PHP script, which is designed to block any unwanted mail and forward the rest on to my private address. The basic mechanics are working fine; however, I can't get the mail() function to send the headers properly (which is especially important for HTML-formatted mails).

    First I parse out the headers (and also catch the subject specifically) from the e-mail with the following code:
    Code:
    $subject = "";
    $headers = "";
    $message = "";
    $splittingheaders = true;
    
    for ($i=0; $i<count($lines); $i++) {
      if ($splittingheaders) {
        // this is a header
        $headers .= $lines[$i]."\r\n";
        if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
          $subject = $matches[1];
        }
      } else {
        // not a header, but message
        $message .= $lines[$i]."\n";
      }
    
      if (trim($lines[$i])=="") {
        // empty line, header section has ended
        $splittingheaders = false;
      }
    }
    Then, after parsing the appropriate fields for spam indicators of my choosing, I send out the e-mail with the following snippet (yes, $my_address is defined):

    Code:
    mail($my_address,$subject,$message,$headers);
    but instead i receive the email like so (items in parentheses represent the contents of the variables indicated):

    Originally posted by Actual Headers
    From: (my @cpanel67.gzo.com address)
    To: ($my_address)
    Subject: ($subject)
    Date: 2008-02-04 08:24 PM
    Originally posted by Body of Message
    ($headers)
    ($message)
    When I output the value of $headers to a file, it shows all the original headers, including the "From: " header, yet the headers wind up stuffed into the body, and the from address on the final message is my cpanel address. It looks almost like the mail() function is intentionally stuffing the headers into the body and rewriting its own default headers.

    Can anyone tell me why this is happening, and help me figure out what I need to do to fix that?
Working...