读邮件正文

[php] /* * 读取邮件正文body */ public function bodys(){ vendor('PHPMailer.imap');//导入收邮件类 $path='Upload/mailfile/';// 附件保存地址 //set_time_limit(0); $emailBody=M('EmailMaillist');//读收邮件 $email_attach=M('EmailAttach');//附件表 $mailInfo=M("EmailInfo");// 用户邮件配置表 $Model=new Model(); $msessage_id = $_GET['msessage_id']; $udate = $_GET['udate']; $msgno = $_GET['msgno']; $EmailAddress = $_GET['email']; $where['sendtime']=$udate; $where['msessage_id']=$msessage_id; $sql = "select ID,is_download from oa_email_maillist where sendtime='".$udate."' and msessage_id='".$msessage_id."'"; $rlt = $Model->query($sql); $is_download = $rlt[0]['is_download']; $mail_id = $rlt[0]['ID']; if($is_download==0){ $d = 1; $uid=23; $sql = "select * from oa_email_info where uid=$uid"; $rlt = $Model->query($sql); $row = $rlt[0]; $username =$row['user_login_user']; $password = $row['user_login_psw']; $EmailAddress = $row['user_login_mail']; $mailserver = $row['pop3'];//收邮件服务器 $servertype = $row['servertype'];//收件类型 pop3 ,imap[默认] $port = $row['pop3_port']; $mail = new imap($username,$password,$EmailAddress,$mailserver,$servertype,$port,false); $mail->open(); $mail->setType(); $mail->fetch_structure($msgno); $attachArr = $mail->getAllAttachment($msgno); $i = 1; $inlineAttach = array(); if(!empty($attachArr)){ foreach ($attachArr as $rows){ $filename = $rows['filename']; $details = $rows['details']; $attachtype = $rows["attachtype"]; $filesize = $rows["filesize"]; $inlineID = $rows['inline_id']; $downloadname = $mail->deliverAttach($filename,$details,$path,$i); if($attachtype=="inline"){ $inlineAttach[$i-1]["filename"] = $filename; $inlineAttach[$i-1]["downloadname"] = $downloadname; $inlineAttach[$i-1]["filesize"] = $filesize; $inlineAttach[$i-1]["attachtype"] = $attachtype; $inlineAttach[$i-1]["inline_id"] = $inlineID; } $isql = "insert into oa_email_attach set mail_id='".$mail_id."',filename='".$filename."', filename_tmp='".$downloadname."',download_time=now()"; $Model->execute($isql); $i++; } } $content = $mail->getBody($msgno); $content = $mail->replaceImg($inlineAttach,$content); $condition['sendtime']=$udate; $condition['msessage_id']=$msessage_id; $condition['uid']=23;//用户id $data_u['content']=addslashes($content); $data_u['is_download']=$d; // $emailBody->where($condition)->save($data_u); $sql = "update oa_email_maillist set content='".addslashes($content)."',is_download='".$d."' where sendtime='".$udate."' and msessage_id='".$msessage_id."'"; $Model->execute($sql); if($d){ while(true){ if($mail->deleteMails($msgno)){ if($mail->emptyDeletebox()){ $sql = "update oa_email_maillist set msgno=0 where sendtime='".$udate."' and msessage_id='".$msessage_id."'"; $Model->execute($sql); $wheremsgno['msgno']=array('neq',0); $wheremsgno['msessage_id']=$msessage_id; //$sql =' "select ID from oa_email_maillist where msgno<>0 and msessage_id=".$msessage_id."order by msgno asc"'; $rlt =$emailBody->where($wheremsgno)->order('msgno asc')->field('ID')->select(); //$rlt=$Model->query($sql); //查询不等于0 for($k=1;$k<count($rlt);$k++){ $ID = $rlt['ID']; $usql = "update oa_email_maillist set msgno=".$i." where ID='".$ID."'"; $Model->execute($usql); dump($rlt); } break; } } } } $mail->close(); } $sql = "select * from oa_email_maillist where sendtime='".$udate."' and msessage_id='".$msessage_id."'"; $rlt = $Model->query($sql); $row = $rlt[0]; $content = $row['content']; //$asql = "select * from oa_email_attach where mail_id='".$mail_id."'"; $arlt =$email_attach->where('mail_id='.$mail_id)->select(); if(count($arlt)!=0){ //dump($arlt); echo "附件:"; for($i=0;$i<count($arlt);$i++){ $filename = $arlt[0]['filename']; $filename_tmp = $arlt[0]['filename_tmp']; echo strtolower($filename)."&nbsp;&nbsp;"; echo "<a href=\"".$path.$filename_tmp."\" target=\"_blank\">查看</a><br>"; } } echo $content; } [/php]

你可能感兴趣的:(邮件)