当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。