當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP imap_reopen()用法及代碼示例


PHP-IMAP 函數可幫助您訪問電子郵件帳戶,IMAP 代表I互聯網M艾爾A訪問權限Protocol 使用這些函數您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

這個imap_reopen()函數接受一個表示 IMAP 流的資源值,一個表示郵箱 url/名稱的字符串值作為參數,並將給定的流重新打開到新郵箱。

用法

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

參數

Sr.No 參數及說明
1

imap_stream (Mandatory)

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

2

mailbox(Mandatory)

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

3

options (Optional)

這是一個表示可選參數的整數值,它可以是以下一個或多個 -

  • OP_READONLY

  • OP_ANONYMOUS

  • OP_HALFOPEN

  • CL_EXPUNGE

  • OP_DEBUG

4

retries (Optional)

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

返回值

此函數返回 s 布爾值,成功時為 TRUE,失敗時為 FALSE。

PHP版本

這個函數最初是在 PHP 版本 4 中引入的,並且適用於所有後續版本。

Example

下麵的例子演示了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 - imap_reopen() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。