网站地图    收藏   

主页 > php专栏 > php应用 >

PHP邮件接收与发送类实现程序详解 - php高级应用

来源:自学PHP网    时间:2014-11-27 22:16 作者: 阅读:次

[导读] 我想使用邮件接收类的朋友可能比较少,但是发送邮件的类使用的朋友比较多啊,下面我来分别给大家介绍PHP邮件接收与发送类实现程序详解,希望对...

PHP邮件接收与发送类实现程序详解

我想使用邮件接收类的朋友可能比较少,但是发送邮件的类使用的朋友比较多啊,下面我来分别给大家介绍PHP邮件接收与发送类实现程序详解,希望对大家所有帮助哦。

主要的改进如下:

1、新增了listMessages方法,用于列表邮件列表,且带有分页功能,更加方便调用:

  1. /** 
  2.  * listMessages - 获取邮件列表 
  3.  * @param $page - 第几页 
  4.  * @param $per_page - 每页显示多少封邮件 
  5.  * @param $sort - 邮件排序,如:array('by' => 'date', 'direction' => 'desc') 
  6.  * */ 
  7. function listMessages($page = 1, $per_page = 25, $sort = null){} 

2、新增了两个编码转换的方法,主要用于对邮件的相关信息进行编码转换,调用方法如下:

  1. include("receivemail.class.php"); 
  2. $obj = receiveMail('abc@abc.com','xxxxxx','abc@abc.com','pop.abc.com','pop3','110', false); 
  3. $obj->connect(); 
  4. $maillist = $obj->listMessages(); 
  5. print_r($maillist); 
  6. 运行结果大致如下: 
  7. Array 
  8. ( 
  9.     [res] => Array 
  10.         ( 
  11.          [0] => stdClass Object 
  12.           ( 
  13.            [subject] => 解决PHP邮件接收类的乱码问题 
  14.            [from] => xxx <xxx@phper.org.cn> 
  15.            [to] => abc <abc@abc.com> 
  16.            [date] => Mon, 28 Jan 2013 14:23:06 +0800 (CST) 
  17.            [message_id] => <2afc51061915f95-00004.Richmail.00037000523146269922@xxx.com> 
  18.                     [size] => 42259 
  19.                     [uid] => 1 
  20.                     [msgno] => 1 
  21.                     [recent] => 1 
  22.                     [flagged] => 0 
  23.                     [answered] => 0 
  24.                     [deleted] => 0 
  25.                     [seen] => 0 
  26.                     [draft] => 0 
  27.                     [body] => 邮件内容 
  28.           ) 
  29.         ) 
  30.  [start] => 1 
  31.     [limit] => 25 
  32.     [sorting] => Array 
  33.         ( 
  34.             [by] =>  
  35.             [direction] =>  
  36.         ) 
  37.     [total] => 47 
  38.     [pages] => 2 
  39. ) 

receivemail.class.php类文件,代码如下:

  1. <?php 
  2. class receiveMail 
  3. { 
  4.  var $server=''; 
  5.  var $username=''; 
  6.  var $password=''; 
  7.  
  8.  var $marubox='';      
  9.  
  10.  var $email='';    
  11.  
  12.  function receiveMail($username,$password,$EmailAddress,$mailserver='localhost',$servertype='pop',$port='110',$ssl = false) //Constructure 
  13.  { 
  14.   if($servertype=='imap') 
  15.   { 
  16.    if($port=='') $port='143';  
  17.    $strConnect='{'.$mailserver.':'.$port. '}INBOX';  
  18.   } 
  19.   else 
  20.   { 
  21.    $strConnect='{'.$mailserver.':'.$port. '/pop3'.($ssl ? "/ssl" : "").'}INBOX';  
  22.   } 
  23.   $this->server   = $strConnect; 
  24.   $this->username   = $username; 
  25.   $this->password   = $password; 
  26.   $this->email   = $EmailAddress; 
  27.  } 
  28.  
  29.  function connect() //Connect To the Mail Box 
  30.  { 
  31.   $this->marubox=@imap_open($this->server,$this->username,$this->password); 
  32.    
  33.   if(!$this->marubox) 
  34.   { 
  35.    echo "Error: Connecting to mail server"; 
  36.    exit; 
  37.   } 
  38.  } 
  39.  
  40.  function listMessages($page

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论