예제 #1
0
 public function actionIndex()
 {
     $model = new Receive();
     $mailaccount = setting::find()->one();
     $user = $mailaccount->user;
     $password = $mailaccount->password;
     $username = $mailaccount->username;
     $receivehost = $mailaccount->receivehost;
     $receiveapply = "imap";
     $receiveport = $mailaccount->receiveport;
     $obj = new receiveMail($user, $password, $username, $receivehost, $receiveapply, $receiveport, 'ture');
     $obj->connect();
     $tot = $obj->getTotalMails();
     for ($i = $tot; $i > $tot - 5; $i--) {
         $model = new Receive();
         $head = $obj->getHeaders($i);
         //            var_dump($head);
         $head['subject'] = imap_mime_header_decode($head['subject'])[0]->text;
         $head['from'] = imap_mime_header_decode($head['from'])[0]->text;
         $head['fromName'] = imap_mime_header_decode($head['fromName'])[0]->text;
         $attachments = $obj->GetAttach($i, "c:/receiveattachment");
         $attach = "";
         if ($attachments != "") {
             $attach = $attachments;
             var_dump($attach);
             $encode = mb_detect_encoding($attachments, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5", "EUC-CN"));
             if ($encode == "EUC-CN") {
                 $encode = "GB2312";
             }
             if ($encode != "UTF-8") {
                 $attach = iconv("{$encode}", "UTF-8//IGNORE", $attachments);
             }
         }
         var_dump($attach);
         $model->subject = $head['subject'];
         $model->sender = $head['from'];
         //            echo $i.$head['date']."</br>";
         //            echo $i.strtotime($head['date'])."</br>";
         //            echo $i.date("Y-m-d H:i:s",strtotime($head['date']))."</br>";
         $model->sendtime = date("Y-m-d H:i:s", strtotime($head['date']));
         $model->text = $obj->getBody($i);
         $model->attachment = $attach;
         var_dump($model);
         //            $model->sendtime=$head['date'];
         $model->save();
         //            echo $i.$head['date'];
     }
     $obj->close_mailbox();
 }
예제 #2
0
 public function actionReceiver()
 {
     $model = new Receive();
     error_reporting(E_ALL || ~E_WARNING || ~E_NOTICE);
     $mailaccount = setting::find()->one();
     $user = $mailaccount->user;
     $password = $mailaccount->password;
     $username = $mailaccount->username;
     $receivehost = $mailaccount->receivehost;
     $receiveapply = "imap";
     $receiveport = $mailaccount->receiveport;
     $obj = new receiveMail($user, $password, $username, $receivehost, $receiveapply, $receiveport, 'ture');
     $obj->connect();
     $tot = $obj->getTotalMails();
     //查看邮箱是否有新邮件
     $old_email_count = Email::find()->count();
     for ($i = $tot; $i > $old_email_count; $i--) {
         $model = new Receive();
         $head = $obj->getHeaders($i);
         $head['subject'] = imap_mime_header_decode($head['subject'])[0]->text;
         $head['from'] = imap_mime_header_decode($head['from'])[0]->text;
         $head['fromName'] = imap_mime_header_decode($head['fromName'])[0]->text;
         $text = $obj->getBody($i);
         $encode = mb_detect_encoding($text, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5", "EUC-CN"));
         if ($encode == "EUC-CN") {
             $encode = "GB2312";
         }
         if ($encode != "UTF-8") {
             $text = iconv("{$encode}", "UTF-8", $text);
         }
         $model->text = $text;
         $attachments = $obj->GetAttach($i, "../attachment/receiveattachment");
         $attach = "";
         if ($attachments != "") {
             $attach = $attachments;
             $encode = mb_detect_encoding($attachments, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5", "EUC-CN"));
             if ($encode == "EUC-CN") {
                 $encode = "GB2312";
             }
             if ($encode != "UTF-8") {
                 $attach = iconv("{$encode}", "UTF-8", $attachments);
             }
         }
         $model->subject = $head['subject'];
         $model->sender = $head['from'];
         $model->sendtime = date("Y-m-d H:i:s", strtotime($head['date']));
         $model->attachment = $attach;
         $model->save();
     }
     $obj->close_mailbox();
 }