PHP - imap_reopen() 函式



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

**imap_reopen()** 函式接受一個表示 IMAP 流的資源值,一個表示郵箱 URL/名稱的字串值作為引數,並將給定的流重新開啟到一個新的郵箱。

語法

imap_reopen($mailbox, $mailbox [$options, $n_retries);

引數

序號 引數 & 描述
1

imap_stream (必填)

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

2

mailbox(必填)

這是一個字串值,表示郵箱的名稱/URL。它包含伺服器名稱、郵箱路徑。

3

options (可選)

這是一個整數值,表示可選引數,可以是以下一個或多個:

  • OP_READONLY

  • OP_ANONYMOUS

  • OP_HALFOPEN

  • CL_EXPUNGE

  • OP_DEBUG

4

retries (可選)

這是一個整數值,表示最大嘗試次數。

返回值

此函式返回一個布林值,成功時為 TRUE,失敗時為 FALSE。

PHP 版本

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

示例

以下示例演示了 **imap_reopen()** 函式的使用。

<html>
   <body>
      <?php
	      //Establishing connection
         $mailbox = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $stream = imap_open($mailbox, $id, $pwd);
         //Reopening a mailbox
         $res = imap_reopen($stream, $mailbox);
         
         if($res){
            print("Connection established....");
         }else{
            print("Connection failed");
         }
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....

示例

以下是上述函式使用可選引數的示例。

<html>
   <body>
      <?php
         //Establishing the connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $stream = imap_open($url, $id, $pwd);		 

         //Optional parameters
         $options = OP_READONLY;
         $retries = 10;		 
         $res = imap_reopen($stream, $url, $options, $retries);
       
         if($res){
            print("Connection established....");
         } else {
            print("Connection failed");
         }
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....

示例

<html>
   <body>
      <?php
         //Establishing the connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $stream = imap_open($url, $id, $pwd);		 
		 		 
         $submbox = imap_listmailbox($stream, $url, "*");
         if (!$submbox) {
            print("Issue occurred");
            print("<br>");
         } else {
            foreach ($submbox as $name) {
               print($name . PHP_EOL);
               print("<br>");

            }
         }   
         $test = imap_reopen($stream, $url);
         if ($test == false) {
            print("Mailbox re-openeed successfully");
            print("<br>");
         }
      ?>
   </body>
</html>

輸出

這將產生以下輸出:

{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX
php_function_reference.htm
廣告