PHP邮件接收与发送类实现程序详解
我想使用邮件接收类的朋友可能比较少,但是发送邮件的类使用的朋友比较多啊,下面我来分别给大家介绍PHP邮件接收与发送类实现程序详解,希望对大家所有帮助哦。
主要的改进如下:
1、新增了listMessages方法,用于列表邮件列表,且带有分页功能,更加方便调用:
-
-
-
-
-
-
- function listMessages($page = 1, $per_page = 25, $sort = null){}
2、新增了两个编码转换的方法,主要用于对邮件的相关信息进行编码转换,调用方法如下:
- include("receivemail.class.php");
- $obj = receiveMail('abc@abc.com','xxxxxx','abc@abc.com','pop.abc.com','pop3','110', false);
- $obj->connect();
- $maillist = $obj->listMessages();
- print_r($maillist);
- 运行结果大致如下:
- Array
- (
- [res] => Array
- (
- [0] => stdClass Object
- (
- [subject] => 解决PHP邮件接收类的乱码问题
- [from] => xxx <xxx@phper.org.cn>
- [to] => abc <abc@abc.com>
- [date] => Mon, 28 Jan 2013 14:23:06 +0800 (CST)
- [message_id] => <2afc51061915f95-00004.Richmail.00037000523146269922@xxx.com>
- [size] => 42259
- [uid] => 1
- [msgno] => 1
- [recent] => 1
- [flagged] => 0
- [answered] => 0
- [deleted] => 0
- [seen] => 0
- [draft] => 0
- [body] => 邮件内容
- )
- )
- [start] => 1
- [limit] => 25
- [sorting] => Array
- (
- [by] =>
- [direction] =>
- )
- [total] => 47
- [pages] => 2
- )
receivemail.class.php类文件,代码如下:
- <?php
- class receiveMail
- {
- var $server='';
- var $username='';
- var $password='';
-
- var $marubox='';
-
- var $email='';
-
- function receiveMail($username,$password,$EmailAddress,$mailserver='localhost',$servertype='pop',$port='110',$ssl = false)
- {
- if($servertype=='imap')
- {
- if($port=='') $port='143';
- $strConnect='{'.$mailserver.':'.$port. '}INBOX';
- }
- else
- {
- $strConnect='{'.$mailserver.':'.$port. '/pop3'.($ssl ? "/ssl" : "").'}INBOX';
- }
- $this->server = $strConnect;
- $this->username = $username;
- $this->password = $password;
- $this->email = $EmailAddress;
- }
-
- function connect()
- {
- $this->marubox=@imap_open($this->server,$this->username,$this->password);
-
- if(!$this->marubox)
- {
- echo "Error: Connecting to mail server";
- exit;
- }
- }
-
- function listMessages($page