PHP - imap_fetch_overview() 函式



PHP−IMAP 函式幫助您訪問電子郵件帳戶,IMAP 代表 **I**nternet **M**ail **A**ccess **P**rotocol,使用這些函式您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

**imap_fetch_overview()** 函式接受表示 IMAP 流的資源值,表示郵箱中訊息的字串值作為引數,並返回指定方法的標題資訊的概述。

語法

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

引數

序號 引數及描述
1

imap_stream(必填)

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

2

str(必填)

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

3

options(可選)

這是一個表示可選值 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_function_reference.htm
廣告