PHP - imap_scanmailbox() 函式



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

imap_scanmailbox() 函式是 imap_listscan() 的別名。它接受表示 IMAP 流的資源值,三個表示伺服器規範、郵箱層次結構和文字的字串值作為引數,並搜尋包含給定文字的郵箱,並將匹配的郵箱名稱以陣列的形式返回。

語法

imap_scanmailbox($imap_stream, $ref, $pattern, $txt);

引數

序號 引數及描述
1

imap_stream (必填)

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

2

ref (必填)

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

3

pattern (必填)

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

4

txt (必填)

這是一個表示要搜尋的文字的字串值。

返回值

此函式返回一個數組,其中包含包含給定文字的郵箱的名稱。

PHP 版本

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

示例

此示例演示了 imap_scanmailbox() 函式的使用方法:

<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>");
		 
         //list of mailboxes
         $res = imap_scanmailbox($imap, $url, "%", "");
         print_r($res);		 

         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Test_mail1
Test_mail2
Test_mail3
php_function_reference.htm
廣告