list() and explode() help needed.
Posted: Fri Nov 12, 2010 11:09 pm
Okay, So i've been hacking away at this bounced email parsing script for 6 hours straight now.
I need away to extract a variable from the header of the bounced email. The email format is this:
user-VARIABLE I NEED-bounce@domain.com
I am able to get the bounced emails piped correctly to the script and it updates mySQL correctly when I run the script with a $_GET var in the URL.
This is the code I'm using to try to extract my variable from the email address. I'm almost 100% certain that this is the culprit in all this.
Just in case thats not the issue, here is the whole parser.
Any help here is appreciated. I'm about to start ripping hair out...
I need away to extract a variable from the header of the bounced email. The email format is this:
user-VARIABLE I NEED-bounce@domain.com
I am able to get the bounced emails piped correctly to the script and it updates mySQL correctly when I run the script with a $_GET var in the URL.
This is the code I'm using to try to extract my variable from the email address. I'm almost 100% certain that this is the culprit in all this.
Code: Select all
list($part1,$dum1) = explode("-bounce@domain.com", trim($to) );
list($dum2,$unsublink) = explode("user-", $part1);
Code: Select all
// Reading in the email
$fd = fopen("php://stdin", "r");
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// Parsing the email
$lines = explode("\n", $email);
$stillheaders=true;
for ($i=0; $i < count($lines); $i++) {
if ($stillheaders) {
// 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
break;
// Optionally you can read out the message also, instead of the break:
//$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$stillheaders = false;
}
}
list($part1,$dum1) = explode("-bounce@domain.com", trim($to) );
list($dum2,$unsublink) = explode("user-", $part1);
Any help here is appreciated. I'm about to start ripping hair out...