My web developer is really busy, so I’m trying to jump in and see if I can get this figured out. Bounced emails are coming in, and we need to extract the EmailID custom header, which purposely is not prefaced with X- He setup a while loop to parse through the entire body content of the email. For my code example below, I just put one line of what would normally be in the full email, into $bodyContent.
<?php
$bodyContent = "EmailID: 12345\r\n";
$separator = "\r\n";
$line = strtok($bodyContent, $separator);
while ($line !== false) {
if (strpos($line, "EmailID:")) {
list($lineKey, $extractedHeader) = explode(' ', $line);
}
if (strpos($line, "EmailID:")) {
if (preg_match_all('/<(.*?)>/',$line,$match1)) {
$extractedHeader= $match1[1][0];
}
}
$line = strtok( $separator ); // Not sure what this does
}
// End while loop
$finalEmailID = preg_replace('~\D~', '', $extractedHeader);
echo $finalEmailID;
?>
How do I go about getting the emailID, which in this case is 12345? Which of the two main IF statements inside the while loop will best do the job?
Thank you @rpkamp for your input. However, when I try to add your simple example to my code it leads to segmentation faults, which are very difficult to troubleshoot because they never state an actual error message or the line number that caused it. Thoughts?