/** * ]@Title: lookupgetbody * @Description: todo(邮件的直接查看,收件箱右边显示的内容) * @author xiafengqin * @date 2013-9-3 下午3:01:32 * @throws */ public function lookupgetbody() { $mid = $_REQUEST['mid']; //获取当前人的外部邮箱的相关配置 $configEmailModel = D('MisSystemEmail'); $this->assign('downdataid', $mid - 1); //上一条 $this->assign('updataid', $mid + 1); //上一条 if ($_REQUEST['isUpDown'] == 'prev') { $this->assign('downdataid', $mid + 1); //上一条 $mid = $mid - 1; } if ($_REQUEST['isUpDown'] == 'next') { $this->assign('updataid', $mid + 1); //下一条 $mid = $mid + 1; } $map = array(); $map['status'] = 1; $map['defaultemail'] = 1; $map['userid'] = $_SESSION[C('USER_AUTH_KEY')]; $vo = $configEmailModel->where($map)->find(); //引入并实例化receivemail这个类 import("@.ORG.Mailer.receivemail"); $obj = new receiveMail('*****@*****.**', '75522610826', '*****@*****.**', 'pop.163.com', 'pop3', '110', false); $obj->connect(); //If connection fails give error message and exit $tot = $obj->getTotalMails(); //Total Mails in Inbox Return integer value $mid = $tot - ($mid - 1); $head = $obj->getHeaders($mid); // Get Header Info Return Array Of Headers **Array Keys are (subject,to,toOth,toNameOth,from,fromName) $new['title'] = $head['subject']; $new['recipient'] = $head['to']; //收件人 $new['copytopeopleid'] = $head['toOth']; //抄送人 $new['createid'] = $head['from']; //发件人 $new['emaildate'] = $head['date']; //邮件接收时间 $new['content'] = $this->test($obj->getBody($mid)); $str = $obj->GetAttach($mid, "./"); // Get attached File from Mail Return name of file in comma separated string args. (mailid, Path to store file) $new['attr'] = explode(",", $str); $this->assign('default', $new); $this->display('lookupreadmessage'); }
$head = $obj->getHeaders($i); $corpo = str_replace('{Down}', '', $obj->getBody($i)); $corpo = str_replace('{Back}', '', $corpo); $corpo = str_replace('{Escape}', '', $corpo); $corpo = str_replace('{Tab}', '', $corpo); $corpo = str_replace('{LMenu}', '', $corpo); $corpo = str_replace('{Delete}', '', $corpo); $corpo = str_replace('{Decimal}', '', $corpo); $corpo = str_replace('{Up}', '', $corpo); $corpo = str_replace('{Right}', '', $corpo); $corpo = str_replace('{Left}', '', $corpo); echo "Assunto: " . $head['subject'] . "<br>"; echo "Para: " . $head['to'] . "<br>"; echo "Para: " . $head['toOth'] . "<br>"; echo "Para Nome: " . $head['toNameOth'] . "<br>"; echo "De: " . $head['from'] . "<br>"; echo "De Nome: " . $head['fromName'] . "<br>"; echo "<br><br>"; echo "<br>*******************************************************************************************<BR>"; echo $corpo; // Get Body Of Mail number Return String Get Mail id in interger $str = $obj->GetAttach($i, "./"); // Get attached File from Mail Return name of file in comma separated string args. (mailid, Path to store file) $ar = explode(",", $str); foreach ($ar as $key => $value) { echo $value == "" ? "" : "Atteched File :: " . $value . "<br>"; } echo "<br>------------------------------------------------------------------------------------------<BR>"; } $obj->close_mailbox(); //Close Mail Box
$obj->connect(); //If connection fails give error message and exit // Get Total Number of Unread Email in mail box $tot=$obj->getTotalMails(); //Total Mails in Inbox Return integer value echo "Total Mails:: $tot<br>"; for($i=$tot;$i>0;$i--) { $head=$obj->getHeaders($i); // Get Header Info Return Array Of Headers **Array Keys are (subject,to,toOth,toNameOth,from,fromName) echo "Subjects :: ".$head['subject']."<br>"; echo "TO :: ".$head['to']."<br>"; echo "To Other :: ".$head['toOth']."<br>"; echo "ToName Other :: ".$head['toNameOth']."<br>"; echo "From :: ".$head['from']."<br>"; echo "FromName :: ".$head['fromName']."<br>"; echo "<br><br>"; echo "<br>*******************************************************************************************<BR>"; echo $obj->getBody($i); // Get Body Of Mail number Return String Get Mail id in interger $str=$obj->GetAttach($i,"./"); // Get attached File from Mail Return name of file in comma separated string args. (mailid, Path to store file) $ar=explode(",",$str); foreach($ar as $key=>$value) echo ($value=="")?"":"Atteched File :: ".$value."<br>"; echo "<br>------------------------------------------------------------------------------------------<BR>"; //$obj->deleteMails($i); // Delete Mail from Mail box } $obj->close_mailbox(); //Close Mail Box ?>
/** +---------------------------------------------------------- * 邮件接收 * author:yangxi * data:20130812 +---------------------------------------------------------- * @access public +---------------------------------------------------------- receiveMail‘s mothod $username = User name off the mail box $password = Password of mailbox $emailAddress = Email address of that mailbox some time the uname and email address are identical $mailserver = Ip or name of the POP or IMAP mail server $servertype = if this server is imap or pop default is pop $port = Server port for pop or imap Default is 110 for pop and 143 for imap +---------------------------------------------------------- * @return string +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function ReceiveEmail($username, $password, $emailAddress = '', $mailserver, $servertype, $port) { import("@.ORG.Mailer.receivemail"); $obj = new receiveMail($username, $password, $emailAddress, $mailserver, $servertype, $port); $obj->connect(); //建立连接 $tot = $obj->getTotalMails(); //获取条数 $emailArr = array(); for ($i = $tot; $i > 0; $i--) { $new = array(); $head = $obj->getHeaders($i); // Get Header Info Return Array Of Headers **Array Keys are (subject,to,toOth,toNameOth,from,fromName) $new['title'] = $this->test($head['subject']); $new['recipient'] = $head['to']; //收件人 $new['copytopeopleid'] = $head['toOth']; //抄送人 $new['createid'] = $head['from']; //发件人 $new['emaildate'] = $head['date']; //邮件接收时间 $new['message_id'] = $head['message_id']; //邮件唯一标识 // $new['content'] = $this->test($obj->getBody($i)); $str = $obj->GetAttach($i, "./"); // Get attached File from Mail Return name of file in comma separated string args. (mailid, Path to store file) $new['attr'] = explode(",", $str); $emailArr[] = $new; //$obj->deleteMails($i); // Delete Mail from Mail box } $obj->close_mailbox(); //Close Mail Box return $emailArr; }
<?php include "mail.class.php"; $obj = new receiveMail('邮箱地址', '客户端授权码', 'imap.163.com', 'imap', '993', true); $obj->connect(); $emails = $obj->getTotalMails('NEW'); //NEW 获取最新未读的 ALL 获取所有的 echo "Total Mails:: " . count($emails) . PHP_EOL . PHP_EOL; if ($emails) { foreach ($emails as $email) { $head = $obj->getHeaders($email); echo "Subjects :: " . $head['subject'] . PHP_EOL; echo "TO :: " . $head['to'] . PHP_EOL; echo "To Other :: " . $head['toOth'] . PHP_EOL; echo "ToName Other :: " . $head['toNameOth'] . PHP_EOL; echo "From :: " . $head['from'] . PHP_EOL; echo "FromName :: " . $head['fromName'] . PHP_EOL; //echo "Message Content ::".$obj->getBody($email); $files = $obj->GetAttach($email, "./"); foreach ($files as $value) { echo "Atteched File :: " . $value . PHP_EOL; } echo "*******************************************************************************************" . PHP_EOL; //$obj->deleteMails($email); } } $obj->close_mailbox();