PHP - imap_mailboxmsginfo() 函式



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

imap_mailboxmsginfo() 函式接受一個表示 IMAP 流的資源值,並檢索有關當前郵箱的資訊,並將其作為物件返回。

語法

imap_mailboxmsginfo($imap_stream);

引數

序號 引數及描述
1

imap_stream (必填)

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

返回值

此函式在成功的情況下返回一個表示當前郵箱資訊的 物件值,在失敗的情況下返回布林值 FALSE。

PHP 版本

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

示例

以下示例演示了 imap_mailboxmsginfo() 函式的用法:

<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 message info
         print("Message Info: "."<br>");
         $body = imap_mailboxmsginfo($imap,);
         print_r($body);
         
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
Message Info:
stdClass Object (
   [Unread] => 0 [Deleted] => 0 [Nmsgs] => 7 [Size] => 34132 
   [Date] => Wed, 28 Oct 2020 22:11:14 +0530 (India Standard Time) 
   [Driver] => imap 
   [Mailbox] => {imap.gmail.com:993/imap/notls/ssl/novalidate-cert/user="tutorialspoint.test@gmail.com"}INBOX 
   [Recent] => 0 
)

示例

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

<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 message info
         print("Message Info: "."<br>");
         $info = imap_mailboxmsginfo($imap,);
         print( "Date: ". $info->Date . "<br />\n") ;
         print("Driver: ". $info->Driver . "<br />\n");
         print("Mailbox: ". $info->Mailbox . "<br />\n");
         print("Messages: ". $info->Nmsgs . "<br />\n");
         print("Recent: ". $info->Recent . "<br />\n");
         print("Unread: ". $info->Unread . "<br />\n");
         print("Deleted: ". $info->Deleted . "<br />\n");
         print("Size: ". $info->Size . "<br />\n");
    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
Message Info:
Date: Wed, 28 Oct 2020 22:20:05 +0530 (India Standard Time)
Driver: imap
Mailbox: {imap.gmail.com:993/imap/notls/ssl/novalidate-cert/user="tutorialspoint.test@gmail.com"}INBOX
Messages: 7
Recent: 0
Unread: 0
Deleted: 0
Size: 34132
php_function_reference.htm
廣告