We pipe incoming email through a PHP script for distribution in our CMS. After processing, we save the raw mail to the filesystem for later debugging, if necessary.
Occasionally, PHP will miss a mail attachment and complain that it can't be found, but if we run the mail parser on the saved raw mail ($mail_text in the code below), it finds the attachment just fine.
This has me wondering if maybe PHP isn't reading in the entire piped email before it tries to process it? Here's how we're reading STDIN and assigning it to a variable:
Can anyone see a scenario where that while loop wouldn't read the whole mail before proceeding to the rest of the code?
Occasionally, PHP will miss a mail attachment and complain that it can't be found, but if we run the mail parser on the saved raw mail ($mail_text in the code below), it finds the attachment just fine.
This has me wondering if maybe PHP isn't reading in the entire piped email before it tries to process it? Here's how we're reading STDIN and assigning it to a variable:
Code:
$fd = fopen("php://stdin", "r");
$mail_text = "";
while(!feof($fd))
{
$mail_text .= fread($fd, 1024);
}
fclose($fd);
Can anyone see a scenario where that while loop wouldn't read the whole mail before proceeding to the rest of the code?