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_get_quotaroot()用法及代碼示例
- PHP imap_getmailboxes()用法及代碼示例
- PHP imap_get_quota()用法及代碼示例
- PHP imap_gc()用法及代碼示例
- PHP imap_header()用法及代碼示例
- PHP imap_last_error()用法及代碼示例
- PHP imap_mutf7_to_utf8()用法及代碼示例
- PHP imap_headerinfo()用法及代碼示例
- PHP imap_lsub()用法及代碼示例
- PHP imap_createmailbox()用法及代碼示例
- PHP imap_fetchtext()用法及代碼示例
- PHP imap_listmailbox()用法及代碼示例
- PHP imap_timeout()用法及代碼示例
- PHP imap_num_msg()用法及代碼示例
- PHP imap_undelete()用法及代碼示例
- PHP imap_mail_move()用法及代碼示例
- PHP imap_status()用法及代碼示例
- PHP imap_utf8_to_mutf7()用法及代碼示例
- PHP imap_clearflag_full()用法及代碼示例
- PHP imap_base64()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - imap_getsubscribed() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。