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


PHP imap_msgno()用法及代碼示例


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

這個imap_msgno()函數接受一個表示 IMAP 流的資源值,一個表示消息 UID 的整數值作為參數,並檢索響應給定 UID 的消息的序列號。

用法

imap_msgno($imap_stream, $uid);

參數

Sr.No 參數及說明
1

imap_stream (Mandatory)

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

2

uid (Mandatory)

這是一個整數值

返回值

此函數返回一個表示消息序列號的整數值。

PHP版本

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

示例

<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 contents of a message
         print("UID of the 1st message:");
         $UID = imap_uid($imap, 1);
         print($UID);
         print("<br>");

         //Retrieving the message number
         $msg = imap_msgno($imap, $UID);
         print($msg); 		 
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Connection established....
UID of the 1st message:19
1

示例

以下是此函數的另一個示例 -

<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 contents of a message
         print("UID of the 1st message:");
         $UID = imap_uid($imap, 1);
         print($UID);
         print("<br>");

         //Retrieving the message number
         $msg = imap_msgno($imap, $UID);
         print($msg);
		   
         $emailData = imap_search($imap, '');
         foreach ($emailData as $msg) {
            $msg = imap_msgno($imap, imap_uid($imap, $msg));
            print($msg);
            print("<br>");
         }    
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這會生成以下輸出 -

Connection established....
UID of the 1st message:19
11
2
3
4
5
6
7

相關用法


注:本文由純淨天空篩選整理自 PHP - imap_msgno() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。