<?php
class popmail
{
var [email protected]
';
var $pwd='1234';
var $popfp;
var $msg;
var $welcome = '歡迎使用叁石pop 接收郵件!';
function popmail($pophost='pop.tom.com',$popport=110)
{
$this->msg = array();
$this->msg[] = $this->welcome;
if ( $this->openpop($pophost,$popport))
{
$this->msg[] = 'pop server connect success!';
}else{
print_r( $this->msg );
}
}
function checkcommon($com,$msg)
{
echo $cod = empty($com)? $this->getservermsg() : $this->putservermsg( $com );
$this->msg[] = ereg( "^/+ok" ,$cod )? $msg : $com .' exec is fauiler!error:'.$cod ;
if( !ereg( "^/+ok" ,$cod ) )
{
echo $cod;
print_r($this->msg);
$this->closestmp();
exit(0);
}
}
function init()
{
$greeting='';
$rn='/r/n';
//$this->checkcommon('',"connect");
//echo $this->putservermsg("apop ".$this->user ." ".$this->pwd.$rn);
// $this->checkcommon("user ",'user');
echo $this->putservermsg("user $this->user".$rn);
echo $this->putservermsg("pass $this->pwd".$rn);
print_r( $this->msg );
}
function openpop($pophost,$popport=110)
{
if( empty($pophost) )
{
$this->msg[] = 'pop host is null!';
return false;
}
if( $fp = fsockopen($pophost,$popport))
{
$this->popfp = $fp;
//echo $this->getservermsg();
return true;
}
$this->msg[] = 'pop server connect failure';
return false;
}
function getservermsg()
{
if( empty( $this->popfp ) )
{
$this->msg[] = 'popfp is null!';
print_r($this->msg);
return false;
}
return fgets( $this->popfp,512);
}
function putservermsg($msg)
{
if( empty( $this->popfp ) )
{
$this->msg[] = 'popfp is null!';
print_r($this->msg);
return false;
}
if( feof($this->popfp))
{
echo "fp is end !";
return false;
}
fputs( $this->popfp , $msg );
return $this->getservermsg();
}
function closestmp()
{
empty($this->popfp) ? '':fclose($this->popfp);
$this->msg[] = "close stmp";
}
}
?>
使用
$pop = new popmail();
$pop->init();
時間倉促,沒有注釋,望見諒!
,歡迎訪問網頁設計愛好者web開發。