分类:
2005-12-29 15:04:56
//+OK 4 message(s) [442118 byte(s)]
//-ERR Unable to log on
$pop_server = "pop3.163.com";
$pop_user = "liuyiwei0301";
$pop_passwd = "********";
$msg_id = 2;
$mailserver=fsockopen($pop_server,110,&$errno,&$errstr,10);
if(!$mailserver){
print("Error: Unable to open socket to pop3 server.");
return false;
// Connection ok
}
// Welcome Message
$buffer=fgets($mailserver,512);
echo $buffer;
// USER
$buffer="USER $pop_user
";
fputs($mailserver,$buffer);
//fgets($mailserver,512);
// PASS
$buffer="PASS $pop_passwd
";
fputs($mailserver,$buffer);
// Authentification OK/ERR
//$buffer=fgets($mailserver,512);
$buffer="RETR $msg_id
";
fputs($mailserver,$buffer);
//$buffer=fgets($mailserver,512);
//echo $buffer;
for(;;) {
$buffer=fgets($mailserver,512);
if(strcasecmp(substr($buffer,0,5),"Date:")==0) {
$mail['date']=substr($buffer,6,strlen($buffer)-6);
}
if(strcasecmp(substr($buffer,0,5),"From:")==0) {
$mail['from'] = htmlspecialchars(substr($buffer,6,strlen($buffer)-6));
}
if(strcasecmp(substr($buffer,0,3),"To:")==0) {
$mail['to'] = htmlspecialchars(substr($buffer,4,strlen($buffer)-4));
}
if(strcasecmp(substr($buffer,0,8),"Subject:")==0) {
$mail['subject'] = imap_mime_header_decode(substr($buffer,9,strlen($buffer)-9));
}
if(strcmp($buffer,"
")==0 || strcmp($buffer,"
")==0 || strcmp($buffer,"
")==0) {
break;
}
}
$mail['text'] = '';
for(;;) {
$buffer=fgets($mailserver,128);
// GAAAAAAHHH! It should not break if regular mail line started with '.'
if(substr($buffer,0,1)==".") {
break;
}
//$mail['text'] .= htmlentities($buffer);
$mail['text'] .= $buffer;
}
echo "
";";
//print_r($mail['subject']);
echo "主题:".$mail['subject'][0]->text."";
echo "发件人:".$mail['from']."";
echo $mail['text'];
echo "