Login   Register  
PHP Classes
elePHPant
Icontem

How to insert message body into database and attachment into tmp

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      POP3 e-mail client  >  All threads  >  How to insert message body into database and attachment into tmp  >  (Un) Subscribe thread alerts  
Subject:How to insert message body into database and attachment into tmp
Summary:How to insert message body into database and attachment into tmp
Messages:6
Author:padam shankhadev
Date:2013-03-18 05:54:24
Update:2013-03-18 11:28:13
 

  1. How to insert message body into database and attachment into tmp   Reply   Report abuse  
Picture of padam shankhadev
padam shankhadev
2013-03-18 05:54:24
I need to help for getting message body and which is inserted into the database as well as i need the attachment also which is save in the tmp folder. Can this is possible?

  2. Re: How to insert message body into database and attachment into   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-03-18 06:14:58 - In reply to message 1 from padam shankhadev
You can use the MIME parser class together with the POP3 class to parse messages and save attachments to files.

  3. Re: How to insert message body into database and attachment into   Reply   Report abuse  
Picture of padam shankhadev
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 &quot;".$pop3->hostname."&quot;.</PRE>\n";
if (($error = $pop3->Login($user, $password, $apop)) == "") {
//echo "<PRE>User &quot;$user&quot; 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 &quot;" . $pop3->hostname . "&quot;.</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

  4. Re: How to insert message body into database and attachment into   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-03-18 11:06:18 - In reply to message 3 from padam shankhadev
If you retrieve the message attachments to strings to use in queries, you need to also add code to save that data to files where you want.

  5. Re: How to insert message body into database and attachment into   Reply   Report abuse  
Picture of padam shankhadev
padam shankhadev
2013-03-18 11:13:04 - In reply to message 4 from Manuel Lemos
Hello sir,

I save the data into the database but, i also need to store attached file into the folder also.

Please Help

  6. Re: How to insert message body into database and attachment into   Reply   Report abuse  
Picture of Manuel Lemos
Manuel Lemos
2013-03-18 11:28:13 - In reply to message 5 from padam shankhadev
As I said, you need to write code to copy the data to a file.