Fork me on GitHub
代码改变世界

收邮件

2012-10-14 22:42  freefei  阅读(283)  评论(0编辑  收藏  举报
[php] /* *收邮件方法2 */ public function receives(){ vendor('PHPMailer.imap');//导入收邮件类 $mailInfo=M("EmailInfo"); $maillist=M('EmailMaillist');//收邮件列表 //$data=$maillist->create(); //$where['uid']=$this->mid; $where['uid']=23; $userinfo=$mailInfo->where($where)->find(); $username = $userinfo['user_name']; $password = $userinfo['user_login_psw']; $EmailAddress = $userinfo['user_login_mail']; $mailserver = $userinfo['pop3'];//收邮件服务器 $servertype = $userinfo['servertype'];//收件类型 pop3 ,imap[默认] $port = $userinfo['pop3_port']; //dump($userinfo); //dump($EmailAddress); $mail = new imap($username,$password,$EmailAddress,$mailserver,$servertype,$port,false); $mail->open(); $mailnum= $mail->getMailList(); for($i=1;$i<=$mailnum;$i++){ $mailHeader = $mail->head($i); //echo "<pre>";print_r($mailHeader);echo "</pre>"; //echo "<br>"; $msgno = $mailHeader['id']; $size = $mailHeader['size']; $messageID = $mailHeader['message_id']; $udate = $mailHeader['udate']; $subject = addslashes($mailHeader['subject']); $charset = $mailHeader['charset']; $sendmail = $mailHeader['from']; $senduser = addslashes($mailHeader['frompersonal']); if($senduser==''){ $senduser = $sendmail; } $fromcharset = $mailHeader['fromcharset']; if($fromcharset=="default"){ $fromcharset = "gb2312"; } if($charset=="default"){ $charset = "gb2312"; } //$csql = "select * from maillist where msessage_id='".$messageID."' and sendtime='".$udate."'"; $condition['msessage_id']=$messageID; $condition['sendtime']=$udate; $csql=$maillist->where($condition)->count(); if($csql==0){ $subject = iconv($charset,"utf-8",$subject); $senduser = iconv($fromcharset,"utf-8",$senduser); $data['title']=$subject; $data['senduser']=$senduser; $data['sendmail']=$sendmail; $data['sendtime']=$udate; $data['msessage_id']=$messageID; $data['msgno']=$msgno; $data['accept_email']=$EmailAddress; $data['uid']=23; $maillist->add($data);//增加 //echo $maillist->getLastSql(); //echo $subject."<br>".$senduser."<br>".$messageID."<br>".$msgno."<br>".$EmailAdress."<br>"; } /*else{ // 更新msgno字段 $wheresave['msessage_id']=$messageID; $wheresave['sendtime']=$udate; $wheresave['uid']=23;// 后面增加的条件用户id为23的 $datas['msgno']=$msgno; $maillist->where($wheresave)->save($datas); }*/ } echo $maillist->getLastSql(); $mail->close(); //echo "接受完毕"; } [/php]
@ https://github.com/ranmufei

校友通微信小程序

校友通微信小程序