require?('pop3.class.inc');
$pop3?=?new?POP3;
//?Connect?to?mail?server
$do?=?$pop3->connect?('your-mail-server-here');
if?($do?==?false)?{
????die($pop3->error);
}
//?Login?to?your?inbox
$do?=?$pop3->login?('your-email-login-name-here',?'password-here');
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?'From:?'?.?htmlentities($email['headers']['From'])?.?'
';
????echo?'Subject:?'?.?htmlentities($email['headers']['Subject'])?.?'
';
????echo?nl2br(htmlentities($email['message']));
????echo?'
';
????//?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?==?'.?"\r\n")?continue;
????????if?($line?==?'?'?.?"\r\n")?continue;
????????if?($line?==?'?'?.?"\r\n")?continue;
????????if?($line?==?'?'?.?"\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;
}
?>