首页 > 开发 > PHP > 正文

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

2024-05-04 23:04:24
字体:
来源:转载
供稿:网友

<?php

class popmail
{
 var $user='[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开发。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表