PHP - imap_getmailboxes() 函式



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

imap_getmailboxes() 函式接受一個表示 IMAP 流的資源值、兩個表示伺服器規範和郵箱層次結構的字串值作為引數,並讀取/檢索郵箱資訊。

語法

imap_getmailboxes($imap_stream, $ref, $pattern);

引數

序號 引數及說明
1

imap_stream (必填)

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

2

ref (必填)

這是一個字串值,表示伺服器規範。

3

pattern (必填)

這是一個字串值,表示郵箱層次結構搜尋的起始位置。

返回值

此函式返回一個物件陣列,其中每個物件都包含有關郵箱的資訊。

PHP 版本

此函式首次引入於 PHP 4 版本,並在所有後續版本中均有效。

示例

以下示例演示了 imap_getMailboxes() 函式的用法。

<html>
   <body>
      <?php
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $mailbox = imap_open($url, $id, $pwd);
         print("Connection established....");
         print("<br>");

         //Retrieving the contents of mail boxes
         $list = imap_getmailboxes($mailbox, $url, "*");
         print_r($list);         
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
Array ( 
   [0] => stdClass Object ( 
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX [attributes] => 64 [delimiter] => / 
   ) 
)

示例

以下是此函式的另一個示例。

<html>
   <body>
      <?php
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $mailbox = imap_open($url, $id, $pwd);
         print("Connection established....");
         print("<br>");

         //Retrieving the contents of mail boxes
         $list = imap_getmailboxes($mailbox, $url, "*");

         if (is_array($list)) {
            foreach ($list as $key => $val) {		   
               print("Name: ".imap_utf7_decode($val->name) ."<br>");
               print("Delimiter: " . $val->delimiter . "<br>");
               print("Attributes: ".$val->attributes . "<br />");
               print("<br>");
            }         
         } else {
            print(“List empty”);
         }
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
Name: {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX
Delimiter: /
Attributes: 64
php_function_reference.htm
廣告