pop3.inc.php,用PHP实现POP3邮件的收取

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 "邮件头的内容:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值