if (!$this->command("$command",3,"+OK"))
return false;
else
{
$this->getresp();
$is_head=true;
while ($this->resp!=".") // . 号是邮件结束的标识
{
if ($this->debug)
$this->outdebug($this->resp);
if (substr($this->resp,0,1)==".")
$this->resp=substr($this->resp,1,strlen($this->resp)-1);
if (trim($this->resp)=="") // 邮件头与正文部分的是一个空行
$is_head=false;
if ($is_head)
$this->head[]=$this->resp;
else
$this->body[]=$this->resp;
$this->getresp();
}
return true;
}
} // end function
function dele($num) // 删除指定序号的邮件,$num 是服务器上的邮件序号
{
if($this->state!="TRANSACTION")
{
$this->err_str="不能删除远程信件,还没有连接到服务器或没有成功登录";
return false;
}
if (!$num)
{
$this->err_str="删除的参数不对";
return false;
}
if ($this->command("DELE $num ",3,"+OK"))
return true;
else
return false;
}
通过以上几个方法,我们已经可以实现邮件的查看、收取、删除的操作,不过别忘了最后要退出,并关闭与服务器的连接,调用下面的这个方法:
Function Close()
{
if($this->connection!=0)
{
if($this->state=="TRANSACTION")
$this->command("QUIT",3,"+OK");
fclose($this->connection);
$this->connection=0;
$this->state="DISCONNECTED";
}
}
应用实例
POP3收取邮件的类在前面的文章中已经给大家做了详细的介绍,下面我们来看看如何应用这个类:
include("pop3.inc.php");
$host="pop.china.com";
$user="boss_ch";
$pass="026007";
$rec=new pop3($host,110,2);
if (!$rec->open()) die($rec->err_str);
echo "open ";
if (!$rec->login($user,$pass)) die($rec->err_str);
echo "login";
if (!$rec->stat()) die($rec->err_str);
echo "共有".$rec->messages."封信件,共".$rec->size."字节大小
";
if ($rec->messages>0)
{
if (!$rec->listmail()) die($rec->err_str);
echo "有以下信件:
";
for ($i=1;$i<=count($rec->mail_list);$i++)
{
echo "信件".$rec->mail_list[$i][num]."大小:".$rec->mail_list[$i][size]."
";
}
$rec->getmail(1);
echo "邮件头的内容: