PHP - imap_unsubscribe() 函数



PHP−IMAP 函数可帮助您访问电子邮件帐户,IMAP 代表 **I**nternet **M**ail **A**ccess **P**rotocol,使用这些函数,您还可以使用 NNTP、POP3 协议和本地邮箱访问方法。

**imap_unsubscribe()** 函数接受表示 IMAP 流的资源值和表示邮箱中消息的整数值作为参数,并取消订阅给定的邮箱。

语法

imap_unsubscribe($imap_stream, $mailbox);

参数

序号 参数及描述
1

imap_stream (必填)

这是一个字符串值,表示 IMAP 流,是 **imap_open()** 函数的返回值。

2

mailbox(必填)

这是一个字符串值,表示邮箱的名称/URL。它包含服务器名称和邮箱路径。

返回值

此函数返回一个布尔值,成功时为 TRUE,失败时为 FALSE。

PHP 版本

此函数首次引入于 PHP 4 版本,并在所有后续版本中均有效。

示例

以下示例演示了 **imap_unsubscribe()** 函数的使用 −

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "[email protected]";
         $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 = "[email protected]";
         $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_function_reference.htm
广告