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


PHP imap_unsubscribe()用法及代碼示例



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

這個imap_unsubscribe()函數接受一個表示 IMAP 流的資源值,一個表示郵箱中消息的整數值作為參數,並從給定的郵箱取消訂閱。

用法

imap_unsubscribe($imap_stream, $mailbox);

參數

Sr.No 參數及說明
1

imap_stream (Mandatory)

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

2

mailbox(Mandatory)

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

返回值

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

PHP版本

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

示例

下麵的例子演示了imap_unsubscribe()函數 -

<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>");
		    
         //Subscribing to the mailbox
         $res = imap_subscribe($imap, $url);
         print("subscribed to a mailbox"."<br>");	
		 
         print("List of subscribed mailboxes"."<br>");	
         print_r(imap_lsub($imap, $url, "*" ));
         print("<br>");
		  		 
         //Unsubscribing to the mailbox
         print("Unsubscribed to the mailboxes:"."<br>");
         imap_unsubscribe($imap, $url);		 
		 
         //Retrieving the list of subscribed mailboxes
         print("List of subscribed mailboxes:"."<br>");
         $list = imap_lsub($imap, $url, "*" );	
         print_r($list);		 

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

輸出

這將生成以下輸出 -

Connection established....
subscribed to a mailbox
List of subscribed mailboxes
Array ( [0] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX )
Unsubscribed to the mailboxes:
List of subscribed mailboxes:

示例

這是上述函數的另一個例子 -

<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>");
		 
         //Creating a mailbox
         $newmailbox1 = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_1";
         $newmailbox2 = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_2";
         $newmailbox3 = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_3";
         imap_createmailbox($imap, imap_utf7_encode($newmailbox1));
         imap_createmailbox($imap, imap_utf7_encode($newmailbox2));
         imap_createmailbox($imap, imap_utf7_encode($newmailbox3));
         print("Mailboxes Created . . . . "."<br>");
		 		 
         //Subscribing to the mailbox
         $res = imap_subscribe($imap, $newmailbox1);
         $res = imap_subscribe($imap, $newmailbox2);
         $res = imap_subscribe($imap, $newmailbox3);
         print("Subscribed to the created mailboxes . . . . "."<br>");


         //List of subscribed mailboxes
         print("List of subscribed mailboxes:"."<br>");
         $list = imap_listsubscribed($imap, $url, "*" );		 
         foreach($list as $ele){
            print($ele."<br>");
         }
		 		 
         //Unsubscribing to mailboxes
         imap_unsubscribe($imap, $newmailbox3);		 

         //List of subscribed mailboxes
         print("List of subscribed mailboxes after unsubscribing:"."<br>");
         $list = imap_listsubscribed($imap, $url, "*" );		 
         foreach($list as $ele){
            print($ele."<br>");
         }	 

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

輸出

這將生成以下輸出 -

Connection established....
Mailboxes Created . . . .
Subscribed to the created mailboxes . . . .
List of subscribed mailboxes:
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_1
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_2
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_3
List of subscribed mailboxes after unsubscribing:
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_1
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_2

相關用法


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