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


PHP imap_getsubscribed()用法及代码示例



PHP-IMAP 函数可帮助您访问电子邮件帐户,IMAP 代表I互联网M艾尔A访问权限Protocol 使用这些函数您还可以使用 NNTP、POP3 协议和本地邮箱访问方法。

这个imap_getsubscribed()函数接受一个表示 IMAP 流的资源值、两个表示服务器规范和邮箱层次结构的字符串值作为参数,并读取/检索有关所有订阅邮箱的信息。

用法

imap_getsubscribed($imap_stream, $ref, $pattern);

参数

Sr.No 参数及说明
1

imap_stream (Mandatory)

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

2

ref (Mandatory)

这是一个表示服务器规范的字符串值。

3

pattern (Mandatory)

这是一个字符串值,表示邮箱层次结构搜索的开始。

返回值

此函数返回一个对象数组,其中每个对象保存有关订阅邮箱的信息。

PHP版本

这个函数最初是在 PHP 版本 4 中引入的,并且适用于所有后续版本。

示例

下面的例子演示了imap_getsubscribed()函数 -

<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);
		 
         //Retrieving the list of subscribed mailboxes
         $list = imap_getsubscribed($imap, $url, "*" );	
         print_r($list);		 

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

输出

这将生成以下输出 -

Connection established....
Array ( 
   [0] => stdClass Object ( 
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX 
      [attributes] => 64 [delimiter] => / 
   ) 
   [1] => stdClass Object ( 
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mail_box1 
      [attributes] => 64 [delimiter] => / 
   ) 
   [2] => stdClass Object ( 
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mail_box2 
      [attributes] => 64 [delimiter] => / 
   ) 
   [3] => stdClass Object (
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_1 
      [attributes] => 64 [delimiter] => / 
   ) 
   [4] => stdClass Object ( 
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.mbox_2 
      [attributes] => 64 [delimiter] => / 
   ) 
)

示例

以下是此函数的另一个示例 -

<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.test_mail1";
         $newmailbox2 = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail2";
         $newmailbox3 = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail3";
         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_getsubscribed($imap, $url, "*" );		 
         print_r($list);
	  
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

输出

这将生成以下输出 -

Connection established....
Mailboxes Created . . . .
Subscribed to the created mailboxes . . . .
List of subscribed mailboxes . . . .
Array ( 
   [0] => stdClass Object (
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX 
      [attributes] => 64 [delimiter] => / 
   ) 
   [1] => stdClass Object (
      [name] => [delimiter] => / 
   ) 
   [9] => stdClass Object ( 
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail1 
      [attributes] => 64 [delimiter] => / 
   ) 
   [10] => stdClass Object (
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail2 
      [attributes] => 64 [delimiter] => / 
   ) 
   [11] => stdClass Object (
      [name] => {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail3 
      [attributes] => 64 [delimiter] => / 
   ) 
)

相关用法


注:本文由纯净天空筛选整理自 PHP - imap_getsubscribed() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。