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:
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):
but instead i receive the email like so (items in parentheses represent the contents of the variables indicated):
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?
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;
}
}
Code:
mail($my_address,$subject,$message,$headers);
Originally posted by Actual Headers
Originally posted by Body of Message
Can anyone tell me why this is happening, and help me figure out what I need to do to fix that?