久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      詳解使用php-imap查詢操作郵件收件箱

      本篇文章帶大家介紹使用php-imap查詢操作郵件收件箱。有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)大家有所幫助。

      最近在業(yè)務(wù)場(chǎng)景里有接收解析用戶主動(dòng)發(fā)送的郵件,使用php-imap實(shí)現(xiàn)了這一需求,記錄一下。

      確定實(shí)現(xiàn)方式

      讀取郵件的協(xié)議有POP3IMAP兩種,區(qū)別:POP3協(xié)議允許電子郵件客戶端下載服務(wù)器上的郵件,但是在客戶端的操作,不會(huì)反饋到服務(wù)器上。IMAP提供webmail與電子郵件客戶端之間的雙向通信,客戶端的操作都會(huì)反饋到服務(wù)器上,對(duì)郵件進(jìn)行的操作,服務(wù)器上的郵件也會(huì)做相應(yīng)的動(dòng)作。

      需求要求處理完用戶的郵件以后,將郵件標(biāo)記為已處理,因此選用IMAP協(xié)議。

      安裝依賴

      本地、服務(wù)器php均需要安裝imap擴(kuò)展。在項(xiàng)目的composer.json中添加php-imap(https://github.com/barbushin/php-imap)擴(kuò)展如下:

      "require": {   "php-imap/php-imap": "^3.1", },

      配置相關(guān)服務(wù)

      namespace applibraryservicemail;  use PhpImapExceptionsConnectionException; use PhpImapMailbox;  /**  * 收郵件服務(wù)郵件API接口  * Class PlayService  * @package applibraryservice  */ class ImapService {     public $path = '{imap.263.net:993/imap/ssl}INBOX';   // IMAP server and mailbox folder     public $login = 'user@263.cn';         // Username for the before configured mailbox     public $password = 'pwd';                   // Password for the before configured username     public $dir = null;        // Directory, where attachments will be saved (optional)     public $encoding = 'UTF-8';   // Server encoding (optional)      public $mailbox;      public function __construct()     {         $this->mailbox = new Mailbox(             $this->path,             $this->login,             $this->password,             $this->dir,             $this->encoding         );     }

      獲取所有未讀郵件列表

      public function unSeenList() {     try {         $mail_ids = $this->mailbox->searchMailbox('UNSEEN');     } catch (ConnectionException $ex) {         die('IMAP connection failed: ' . $ex->getMessage());     } catch (Exception $ex) {         die('An error occured: ' . $ex->getMessage());     }      // If $mailsIds is empty, no emails could be found     if (!$mail_ids) {         die('Mailbox is empty');     }      try {         $info = $this->mailbox->getMailsInfo($mail_ids);     } catch (ConnectionException $ex) {         echo "IMAP connection failed: " . $ex;         die();     }     return ['ids' => $mail_ids, 'list' => $info]; }

      將某些郵件標(biāo)記為已讀

      /**  * @param array $mail_ids  * @return mixed  */ public function markRead($mail_ids) {     return $this->mailbox->markMailsAsRead($mail_ids); }

      搜索指定主題的郵件并標(biāo)記為已讀

      $imap = new ImapService(); $condition = 'UNSEEN  SUBJECT "' . $title . '" SINCE "' . date('Y-m-d', strtotime('-1 days')) . '" FROM ' . $mail; $data['mail'] = $imap->mailbox->searchMailbox($condition); if (!empty($data['mail'])) {     $data['info'] = $imap->mailbox->getMailsInfo($data['mail']);     if ($params['mark'] == 1) {         $data['mark'] = $imap->markRead(array_column($data['info'], 'uid'));     } }

      推薦學(xué)習(xí):《PHP視頻教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)