PHP Classes

php://stdin problem

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  php://stdin problem  >  (Un) Subscribe thread alerts  
Subject:php://stdin problem
Summary:php://stdin problem
Messages:5
Author:Seb Clark
Date:2008-08-20 02:17:43
Update:2008-08-20 03:28:07
 

  1. php://stdin problem   Reply   Report abuse  
Picture of Seb Clark Seb Clark - 2008-08-20 02:17:43
I have setup an aliased email to redirect the email through to a script, part of which is below. I am using the Data method and can get subject, date, sender etc to work, however am having a problem getting the actual body to output in either html or txt format.


// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);

$mime=new mime_parser_class;
$mime->mbox = 0;
$mime->decode_bodies = 1;
$mime->ignore_syntax_errors = 1;
$parameters=array(
// 'File'=>$message_file,
'Data'=>$email,
'SaveBody'=>'/tmp',
'SkipBody'=>0,
);

$mime->Decode($parameters, $decoded);
if($mime->Analyze($decoded[0], $results)) {

$msg_sub=$results['Subject'];
$msg_date=$results['Date'];
$msg_from=$results['From'][0]['address'];
$msg_name=$results['From'][0]['name'];
$msg_cc=$results['Cc'][0]['address'];
$msg_body=$results['Data'];
}

  2. Re: php://stdin problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-08-20 02:36:08 - In reply to message 1 from Seb Clark
First, you can pass the file name 'php://stdin' to the Decode function ussing the File parameter.

As for not accessing the message data, if you use SaveBody option the message parts data goes to files, not to Data parameter returned by Analyze.

  3. Re: php://stdin problem   Reply   Report abuse  
Picture of Seb Clark Seb Clark - 2008-08-20 02:50:03 - In reply to message 2 from Manuel Lemos
Hi,

Thanks for the very quick reply!

I have removed the SaveBody parameter and still have no body output. How Should i use php://stdin with the File Parameter as the following doesnt work

'File'=>'php://stdin',

  4. Re: php://stdin problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-08-20 03:13:19 - In reply to message 3 from Seb Clark
You need to omit the SkipBody parameter too.

As for using php://stdin as File parameter, I don't know why it does not work for you. I just tried it here and it works fine.

  5. Re: php://stdin problem   Reply   Report abuse  
Picture of Seb Clark Seb Clark - 2008-08-20 03:28:07 - In reply to message 4 from Manuel Lemos
Hi Manuel,

Excellent - body is now working :) I am not sure why the php://stdin doesnt work for me as a file, but the fopen works fine, so I will stick with that and the Data parameter.

Thanks again.

Seb