PHP Classes

forward message or save it in the DB

Recommend this page to a friend!

      POP3 e-mail client  >  POP3 e-mail client package blog  >  How Can PHP Read Emai...  >  All threads  >  forward message or save it in the DB  >  (Un) Subscribe thread alerts  
Subject:forward message or save it in the DB
Summary:forward message or save it in the DB
Messages:3
Author:Diana Parvanova
Date:2017-07-20 21:58:25
 

  1. forward message or save it in the DB   Reply   Report abuse  
Picture of Diana Parvanova Diana Parvanova - 2017-07-20 21:58:25
I want to read messages and parse them for some specific information. If for some reason parsing fails I would like to save the message in the DB or forward it so that it can be processed manually.

How do I do this?
Thank you.

  2. Re: forward message or save it in the DB   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2017-07-21 05:45:30 - In reply to message 1 from Diana Parvanova
You can retrieve the whole message to a string and save it to the database or anywhere else. You can use file_get_contents like it is explained in the article.

  3. Re: forward message or save it in the DB   Reply   Report abuse  
Picture of Diana Parvanova Diana Parvanova - 2017-07-21 14:07:14 - In reply to message 2 from Manuel Lemos
Thank you!

I did try to do it with file_get_contents() but I get FALSE as result.

Here is my code (without error handling for simplification ). Can you please review it and tell me what do I do wrong!
Thank you!

stream_wrapper_register('mlpop3', 'pop3_stream');
$pop3=new pop3_class;

//here I set user, pass, server ets.
$pop3->Open();
$pop3->Login($user,$password,$apop);
$pop3->Statistics($messages,$size);
$pop3->GetConnectionName($connection_name);
for ($message=1; $message <= $messages; $message++){
$message_id = $pop3->ListMessages($message, 1);
$message_file='mlpop3://'.$connection_name.'/'.$message;

$mime=new mime_parser_class;
$parameters=array(
'File'=>$message_file,
'SkipBody'=>0,
);
$mime->Decode($parameters, $decoded);
$mime->Analyze($decoded[0], $results);

echo $message_id . "----" .$results['Subject']. "<br>"; // this is OK
//do some parsing here
if(!$parsed_successfully){
$f = file_get_contents($message_file);
var_dump($f);// here the result is FALSE
}

}

$pop3->Close()