Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Piping email to PHP - how does PHP read STDIN?

Status
Not open for further replies.

cmayo

MIS
Apr 23, 2001
159
US
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:

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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top