當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP imap_fetch_overview()用法及代碼示例


PHP-IMAP 函數可幫助您訪問電子郵件帳戶,IMAP 代表I互聯網M艾爾A訪問權限Protocol 使用這些函數您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

這個imap_fetch_overview()函數接受表示 IMAP 流的資源值、表示郵箱中消息的字符串值作為參數,並返回指定方法的標頭信息的概述。

用法

imap_fetch_overview($imap_stream, $str [, $options]);

參數

Sr.No 參數及說明
1

imap_stream (Mandatory)

這是一個表示 IMAP 流的字符串值,返回值imap_open()函數。

2

str (Mandatory)

這是一個字符串值,表示消息編號的序列。您還可以將消息間隔指定為 4:12。

3

options(Optional)

這是一個整數值,表示可選值 FT_UID,如果指定,序列將包含 UID 而不是消息編號。

返回值

此函數返回一個對象數組,每個對象保存有關各個標頭的信息。

PHP版本

這個函數最初是在 PHP 版本 4 中引入的,並且適用於所有後續版本。

示例

下麵的例子演示了imap_fetch_overview()函數 -

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
         
         //Fetching the contents of a message
         print("Overview of the first message:"."<br>");
         $overview = imap_fetch_overview($imap, 1);
         print_r($overview);
    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Connection established....
Overview of the first message:
Array ( 
   [0] => stdClass Object ( 
      [from] => Tutorialspoint [to] => tutorialspoint.test@gmail.com 
      [date] => Thu, 22 Oct 2020 20:10:17 +0530 [message_id] => 
      [size] => 4857 [uid] => 19 [msgno] => 1 [recent] => 0 
      [flagged] => 0 [answered] => 0 [deleted] => 0 
      [seen] => 1 [draft] => 0 [udate] => 1603377656 
   ) 
)

示例

以下是帶有可選參數的上述函數的示例 -

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
         
         //Fetching the contents of a message
         print("Overview of the first message:"."<br>");
         $MC = imap_check($imap);
         $overview = imap_fetch_overview($imap, "1:{$MC->Nmsgs}");
         
         //print_r($overview);
         foreach ($overview as $obj) {
            print($obj->date);
            print("<br>");
            print($obj->size);
            print("<br>");
            print($obj->uid);	
            print("<br>");
         }    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Connection established....
Overview of the first message:
Thu, 22 Oct 2020 20:10:17 +0530
4857
19
Thu, 22 Oct 2020 20:10:52 +0530
4858
20
Sun, 25 Oct 2020 16:11:22 +0530
4880
42
Sun, 25 Oct 2020 17:22:41 +0530
4882
49
Sun, 25 Oct 2020 17:23:10 +0530
4884
50
Sun, 25 Oct 2020 17:24:25 +0530
4883
51

相關用法


注:本文由純淨天空篩選整理自 PHP - imap_fetch_overview() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。