Dear
Manuel
could you help please?
im very new to the class. i could make messages to go to the php page however it looks like a mess. attachments displays as some terrible code.
how can i separate message,subject, attachment ... etc to put it nicely to the db?
this is the php page:
worldwideprojectinfo.com/test/pop3_
...
and my code is below...
<?php
require ('pop3.class.inc');
$pop3 = new POP3;
// Connect to mail server
$do = $pop3->connect ('xxx.xxx.xx');
if ($do == false) {
die($pop3->error);
}
// Login to your inbox
$do = $pop3->login ('xx@xxxx.xx', 'xxxxxxxxxx');
if ($do == false) {
die($pop3->error);
}
// Get office status
$status = $pop3->get_office_status();
if ($status == false) {
die($pop3->error);
}
$count = $status['count_mails'];
if ($count == '0') {
echo 'There are no new e-mails';
}
for ($i = 1; $i <= $count; $i++) {
$email = $pop3->get_mail($i);
if ($email == false) {
echo $pop3->error;
continue;
}
$email = parse_email ($email);
echo '<b>From: </b>' . htmlentities($email['headers']['From']) . '<br />';
echo '<b>Subject: </b>' . htmlentities($email['headers']['Subject']) . '<br /><br />';
//echo nl2br($email['message']);
echo $email['message'];
echo '<hr />';
// TODO: store the e-mail in a database or on the HDD
// Remove from mail server
# $do = $pop3->delete_mail ($i);
# if ($do == false) {
# echo $pop3->error;
# }
}
$pop3->close();
function parse_email ($email) {
// Split header and message
$header = array();
$message = array();
$is_header = true;
foreach ($email as $line) {
if ($line == '<HEADER> ' . "\r\n") continue;
if ($line == '<MESSAGE> ' . "\r\n") continue;
if ($line == '</MESSAGE> ' . "\r\n") continue;
if ($line == '</HEADER> ' . "\r\n") { $is_header = false; continue; }
if ($is_header == true) {
$header[] = $line;
} else {
$message[] = $line;
}
}
// Parse headers
$headers = array();
foreach ($header as $line) {
$colon_pos = strpos($line, ':');
$space_pos = strpos($line, ' ');
if ($colon_pos === false OR $space_pos < $colon_pos) {
// attach to previous
$previous .= "\r\n" . $line;
continue;
}
// Get key
$key = substr($line, 0, $colon_pos);
// Get value
$value = substr($line, $colon_pos+2);
$headers[$key] = $value;
$previous =& $headers[$key];
}
// Parse message
$message = implode('', $message);
// Return array
$email = array();
$email['message'] = $message;
$email['headers'] = $headers;
return $email;
}
?>