php接收邮件,php接收邮件种

php接收邮件种php接收邮件类

receivemail是一个专门用来接收邮件的PHP类,支持POP3和IMAP等邮件协议。可以接收邮件及邮件附件。

中文乱码解决

/**

* decode the subject of chinese

*

* @param string $subject

* @return sting

*/

public function subjectDecode($subject) {

$beginStr = substr($subject, 0, 5);

if($beginStr == '=?ISO') {

$separator = '=?ISO-2022-JP';

$toEncoding = 'ISO-2022-JP';

} else {

$separator = '=?GB2312';

$toEncoding = 'GB2312';

}

$encode = strstr($subject, $separator);

if ($encode) {

$explodeArr = explode($separator, $subject);

$length = count($explodeArr);

$subjectArr = array();

for($i = 0; $i < $length / 2; $i++) {

$subjectArr[$i][] = $explodeArr[$i * 2];

if (@$explodeArr[$i * 2 + 1]) {

$subjectArr[$i][] = $explodeArr[$i * 2 + 1];

}

}

foreach ($subjectArr as $arr) {

$subSubject = implode($separator, $arr);

if (count($arr) == 1) {

$subSubject = $separator . $subSubject;

}

$begin = strpos($subSubject, "=?");

$end = strpos($subSubject, "?=");

$beginStr = '';

$endStr = '';

if ($end > 0) {

if ($begin > 0) {

$beginStr = substr($subSubject, 0, $begin);

}

if ((strlen($subSubject) - $end) > 2) {

$endStr = substr($subSubject, $end + 2, strlen($subSubject) - $end - 2);

}

$str = substr($subSubject, 0, $end - strlen($subSubject));

$pos = strrpos($str, "?");

$str = substr($str, $pos + 1, strlen($str) - $pos);

$subSubject = $beginStr . imap_base64($str) . $endStr;

$subSubjectArr[] = iconv ( $toEncoding, 'utf-8', $subSubject );

// mb_convert_encoding($subSubject, 'utf-8' ,'gb2312,ISO-2022-JP');

}

}

$subject = implode('', $subSubjectArr);

}

return $subject;

}

if(strtolower($sender->mailbox)!='mailer-daemon' && strtolower($sender->mailbox)!='postmaster')

{ $subject = $this->subjectDecode($mail_header->subject);

使用方法如下:

connect(); //If connection fails give error message and exit

// 读取全部信件

$tot = $obj->getTotalMails(); //Total Mails in Inbox Return integer value

echo "收到$tot封邮件::

";

for($i = $tot; $i > 0; $i--)

{

$head = $obj->getHeaders($i); // 读取获取邮件头信息,返回数组 **数组键值为 (subject,to,toOth,toNameOth,from,fromName)

echo "主题 :: ".$head['subject']."

";

echo "收件人 :: ".$head['to']."

";

echo "抄送 :: ".$head['toOth']."

";

echo "发件人 :: ".$head['from']."

";

echo "发件人名称 :: ".$head['fromName']."

";

echo "

";

echo "

*******************************************************************************************

";

echo $obj->getBody($i); // 邮件正文

$str = $obj->GetAttach($i,"./"); // 获取邮件附件,返回的文件名以逗号隔开。 例如. (mailid, Path to store file)

$ar = explode(",",$str);

foreach($ar as $key=>$value)

echo ($value == "") ? "" : "Atteched File :: " . $value . "

";

echo "

------------------------------------------------------

";

//$obj->deleteMails($i); // Delete Mail from Mail box

}

$obj->close_mailbox(); //Close Mail Box

?>

?receivemail.class.php需要imap模块支持。

imap_append : ?? ?附加字符串到指定的邮箱中。

imap_base64 : ?? ?解 base64 编码。

imap_body : ?? ?读信的内文。

imap_check : ?? ?返回邮箱信息。

imap_close : ?? ?关闭 imap 链接。

imap_createmailbox : ?? ?建立新的信箱。

imap_delete : ?? ?标记欲删除邮件。

imap_deletemailbox : ?? ?删除既有信箱。

imap_expunge : ?? ?删除已标记的邮件。

imap_fetchbody : ?? ?从信件内文取出指定部分。

imap_fetchstructure : ?? ?获取某信件的结构信息。

imap_header : ?? ?获取某信件的标头信息。

imap_headers : ?? ?获取全部信件的标头信息。

imap_listmailbox : ?? ?获取邮箱列示。

imap_listsubscribed : ?? ?获取订阅邮箱列示。

imap_mail_copy : ?? ?复制指定信件到它处邮箱。

imap_mail_move : ?? ?移动指定信件到它处邮箱。

imap_num_msg : ?? ?取得信件数。

imap_num_recent : ?? ?取得新进信件数。

imap_open : ?? ?打开 imap 链接。

imap_ping : ?? ?检查 imap 是否连接。

imap_renamemailbox : ?? ?更改邮箱名字。

imap_reopen : ?? ?重开 imap 链接。

imap_subscribe : ?? ?订阅邮箱。

imap_undelete : ?? ?取消删除邮件标记。

imap_unsubscribe : ?? ?取消订阅邮箱。

imap_qprint : ?? ?将 qp 编码转成八位。

imap_8bit : ?? ?将八位转成 qp 编码。

imap_binary : ?? ?将八位转成 base64 编码。

imap_scanmailbox : ?? ?寻找信件有无特定字符串。

imap_mailboxmsginfo : ?? ?取得目前邮箱的信息。

imap_rfc822_write_address : ?? ?电子邮件位址标准化。

imap_rfc822_parse_adrlist : ?? ?解析电子邮件位址。

imap_setflag_full : ?? ?配置信件标志。

imap_clearflag_full : ?? ?清除信件标志。

imap_sort : ?? ?将信件标头排序。

imap_fetchheader : ?? ?取得原始标头。

imap_uid : ?? ?取得信件 uid。

imap_getmailboxes : ?? ?取得全部信件详细信息。

imap_getsubscribed : ?? ?列出所有订阅邮箱。

imap_msgno : ?? ?列出 uid 的连续信件。

imap_search : ?? ?搜寻指定标准的信件。

imap_last_error : ?? ?最后的错误信息。

imap_errors : ?? ?所有的错误信息。

imap_alerts : ?? ?所有的警告信息。

imap_status : ?? ?目前的状态信息。

1 楼

hdnlove

2012-04-10

你好,我想请教下 。我用receivemail  接收邮件 怎么获取数据时   每次加载非常慢呢?您有办法解决吗?

/phprm/28406.htmlwww.phpzy.comtrue/phprm/28406.htmlTechArticlephp接收邮件种 php接收邮件类 receivemail是一个专门用来接收邮件的PHP类,支持POP3和IMAP等邮件协议。可以接收邮件及邮件附件。 中文乱码解决 /** * decode the subject of chinese * * @param string $...

receivemail是一个专门用来接收邮件PHP类,支持POP3和IMAP等邮件协议。 可以接收邮件邮件附件。 include("receivemail.class.php"); 02 // 创建一个 reciveMail 对象 03 $obj = new receiveMail('abc@abc.com','xxxxxx','abc@abc.com','pop.abc.com','pop3','110',false); 04 // 连接到邮件服务器 05 $obj->connect(); //If connection fails give error message and exit 06 // 读取未读邮件数 07 $tot = $obj->getTotalMails(); //Total Mails in Inbox Return integer value 08 09 echo "收到$tot封邮件::"; 10 for($i = $tot; $i > 0; $i--) 11 { 12 $head = $obj->getHeaders($i); // 读取获取邮件头信息,返回数组 **数组键值为 (subject,to,toOth,toNameOth,from,fromName) 13 echo "主题 :: ".$head['subject'].""; 14 echo "收件人 :: ".$head['to'].""; 15 echo "抄送 :: ".$head['toOth'].""; 16 echo "发件人 :: ".$head['from'].""; 17 echo "发件人名称 :: ".$head['fromName'].""; 18 echo ""; 19 echo "*******************************************************************************************"; 20 echo $obj->getBody($i); // 邮件正文 21 $str = $obj->GetAttach($i,"./"); // 获取邮件附件,返回的文件名以逗号隔开。 例如. (mailid, Path to store file) 22 $ar = explode(",",$str); 23 foreach($ar as $key=>$value) 24 echo ($value == "") ? "" : "Atteched File :: " . $value . ""; 25 echo "------------------------------------------------------------------------------------------"; 26 //$obj->deleteMails($i); // Delete Mail from Mail box 27 } 28 $obj->close_mailbox(); //Close Mail Box
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值