php imap收邮件源码_PHP receiveMail实现收邮件功能

用PHP来发邮件,相信大家都不陌生,但读取收件箱的话,接触就少了,这次总结下自己的经验,希望可以帮助大家.

注意:

1.PHP读取收件箱主要是利用imap扩展,所以在使用以下方法前,必须开启imap扩展模块的支持.

2.此方法支持中文,不会乱码,需要保持所有文件的编码的一致性

1.文件结构

c87d3b90e956cde7c908f7b14a0b4bdd.png

2.邮件类 ./mailreceived/receiveMail.class.php

./mailreceived/receiveMail.class.php 文件内容如下:

// Main ReciveMail Class File - Version 1.0 (03-06-2015)

/*

* File: recivemail.class.php

* Description: Reciving mail With Attechment

* Version: 1.1

* Created: 03-06-2015

* Author: Sara Zhou

*/

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) //Constructure

{

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() //Connect To the Mail Box

{

$this->marubox=@imap_open($this->server,$this->username,$this->password);

if(!$this->marubox)

{

return false;

// echo "Error: Connecting to mail server";

// exit;

}

return true;

}

function getHeaders($mid) // Get Header info

{

if(!$this->marubox)

return false;

$mail_header=imap_header($this->marubox,$mid);

$sender=$mail_header->from[0];

$sender_replyto=$mail_header->reply_to[0];

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

{

$subject=$this->decode_mime($mail_header->subject);

$ccList=array();

foreach ($mail_header->cc as $k => $v)

{

$ccList[]=$v->mailbox.'@'.$v->host;

}

$toList=array();

foreach ($mail_header->to as $k => $v)

{

$toList[]=$v->mailbox.'@'.$v->host;

}

$ccList=implode(",", $ccList);

$toList=implode(",", $toList);

$mail_details=array(

'fromBy'=>strtolower($sender->mailbox).'@'.$sender->host,

'fromName'=>$this->decode_mime($sender->personal),

'ccList'=>$ccList,//strtolower($sender_replyto->mailbox).'@'.$sender_replyto->host,

'toNameOth'=>$this->decode_mime($sender_replyto->personal),

'subject'=>$subject,

'mailDate'=>date("Y-m-d H:i:s",$mail_header->udate),

'udate'=>$mail_header->udate,

'toLi

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值