
padam shankhadev - 2013-03-18 07:56:46 -
In reply to message 2 from Manuel Lemos
I used both mime_parser class as well as pop3 class. I save the message body and file name of the attached file into the database.But I also want to save this file into the the folder also so which can downloadable later for further use.I use this code for saving the data into the database
if (($error = $pop3->Open()) == "") {
//echo "<PRE>Connected to the POP3 server "".$pop3->hostname."".</PRE>\n";
if (($error = $pop3->Login($user, $password, $apop)) == "") {
//echo "<PRE>User "$user" logged in.</PRE>\n";
if (($error = $pop3->Statistics($messages, $size)) == "") {
echo "<PRE>There are $messages messages in the mail box with a total of $size bytes.</PRE>\n";
if ($messages > 0) {
$pop3->GetConnectionName($connection_name);
for ($i = 1; $i <= $messages; $i++) {
print $i;
$message_file = 'pop3://' . $connection_name . '/' . $i;
//$message_file = file_get_contents('pop3://'.$connection_name.'/'.$i);
$mime = new mime_parser_class;
/*
* Set to 0 for not decoding the message bodies
*/
$mime->decode_bodies = 1;
$parameters = array(
'File' => $message_file,
/* Read a message from a string instead of a file */
/* 'Data'=>'My message data string', */
/* Save the message body parts to a directory */
//'SaveBody'=>$_SERVER['DOCUMENT_ROOT'].'email/pop3class-2009-02-01/tmp',
/* Do not retrieve or save message body parts */
'SkipBody' => 0
);
$success = $mime->Decode($parameters, $decoded);
if (!$success)
echo '<h2>MIME message decoding error: ' . HtmlSpecialChars($mime->error) . "</h2>\n";
else {
//echo '<h2>MIME message decoding successful</h2>'."\n";
//echo '<h2>Message structure</h2>'."\n";
//echo '<pre>';
//var_dump($decoded[0]);
//echo '</pre>';
if ($mime->Analyze($decoded[0], $results)) {
echo '<h2>Message analysis</h2>'."\n";
echo '<pre>';
print_r($results);
$pos = strpos($results['Subject'], "UID:ID");
$id = substr($results['Subject'], $pos + 6);
//print "Client ID : <pre>$id</pre>";
$body = strip_tags(mysql_real_escape_string($results['Data']));
// echo $body;
$filename = $results['Attachment'][$i]['FileName'];
$query = "INSERT INTO tbl_email (subject,body,filename) VALUES ('$results[Subject]','$body','$filename')";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
//DeleteMessage($i);
$pop3->DeleteMessage($i);
//print "Body is: <pre>$results[Data]</pre>";
print "complete <br />";
//echo '</pre>';
} else
echo 'MIME message analyse error: ' . $mime->error . "\n";
}
}
}
if ($error == "" && ($error = $pop3->Close()) == "")
echo "<PRE>Disconnected from the POP3 server "" . $pop3->hostname . "".</PRE>\n";
}
}
}
if ($error != "")
echo "<H2>Error: ", HtmlSpecialChars($error), "</H2>";
But I am not success to save the file into the folder.
Please give me the solution with sample code.
Thanks