PHP - imap_scan() 函式



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

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

語法

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

引數

序號 引數和描述
1

imap_stream (必填)

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

2

ref (必填)

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

3

pattern (必填)

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

4

txt (必填)

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

返回值

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

PHP 版本

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

示例

此示例演示了 imap_scan() 函式的用法。

<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_scan($imap, $url, "%", "");
         print_r($res);		 

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

輸出

這將生成以下輸出:

Test_mail1
Test_mail2
Test_mail3
php_function_reference.htm
廣告