pop mail 类 很简单的功能(自家用)

此博客展示了一段PHP代码,定义了一个名为popMail的类用于接收邮件。该类包含连接POP服务器、检查命令执行结果、初始化操作等功能,还给出了使用示例,通过创建popMail对象并调用init方法来实现邮件接收。

<?php

class popMail
{
 var $user='sanshi0815@tom.com';
 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();

时间仓促,没有注释,望见谅!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值