PHP-IMAP 函數可幫助您訪問電子郵件帳戶,IMAP 代表I互聯網M艾爾A訪問權限Protocol 使用這些函數您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。
這個imap_check()函數接受一個表示 IMAP 流的資源值作為參數,驗證有關給定郵箱的信息並以對象的形式返回它。
用法
imap_check($imap_stream);
參數
Sr.No | 參數及說明 |
---|---|
1 |
imap_stream (Mandatory) 這是一個表示 IMAP 流的字符串值,返回值imap_open()函數。 |
返回值
此函數返回一個對象,其中包含有關當前郵箱的信息,如果成功,則返回一個布爾值,如果失敗則為 FALSE。
PHP版本
這個函數最初是在 PHP 版本 4 中引入的,並且適用於所有後續版本。
示例
下麵的例子演示了imap_check()函數 -
<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>");
//Fetching the contents of a message
print("Overview of the first message:"."<br>");
$obj = imap_check($imap);
print("<br>");
print("Date:".$obj->Date);
print("<br>");
print("Driver:".$obj−>Driver);
print("<br>");
print("Mailbox:".$obj−>Mailbox);
print("<br>");
print("Nmsgs:".$obj−>Nmsgs);
print("<br>");
print("Recent:".$obj−>Recent);
print("<br>");
//Closing the connection
imap_close($imap);
?>
</body>
</html>
這將生成以下輸出 -
Connection established.... Overview of the first message: Date:Mon, 26 Oct 2020 11:38:26 +0530 (India Standard Time) Driver:imap Mailbox:{imap.gmail.com:993/imap/notls/ssl/novalidate-cert/user="tutorialspoint.test@gmail.com"}INBOX Nmsgs:6 Recent:0
示例
以下是此函數的另一個 -
<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>");
//Fetching the contents of a message
print("Overview of the first message:"."<br>");
$MC = imap_check($imap);
$overview = imap_fetch_overview($imap, "1:{$MC->Nmsgs}");
foreach ($overview as $obj) {
print("<br>");
print_r($obj);
print("<br>");
}
//Closing the connection
imap_close($imap);
?>
</body>
</html>
輸出
這將生成以下輸出 -
Connection established.... Overview of the first message: stdClass Object ( [from] => Sender[to] => tutorialspoint.test@gmail.com [date] => Thu, 22 Oct 2020 20:10:17 +0530 [message_id] => [size] => 4857 [uid] => 19 [msgno] => 1 [recent] => 0 [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 [draft] => 0 [udate] => 1603377656 ) stdClass Object ( [from] => Sender[to] => tutorialspoint.test@gmail.com [date] => Thu, 22 Oct 2020 20:10:52 +0530 [message_id] => [size] => 4858 [uid] => 20 [msgno] => 2 [recent] => 0 [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 [draft] => 0 [udate] => 1603377691 ) stdClass Object ( [from] => Sender[to] => tutorialspoint.test@gmail.com [date] => Sun, 25 Oct 2020 16:11:22 +0530 [message_id] => [size] => 4880 [uid] => 42 [msgno] => 3 [recent] => 0 [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 [draft] => 0 [udate] => 1603622523 ) stdClass Object ( [from] => Sender[to] => tutorialspoint.test@gmail.com [date] => Sun, 25 Oct 2020 17:22:41 +0530 [message_id] => [size] => 4882 [uid] => 49 [msgno] => 4 [recent] => 0 [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 [draft] => 0 [udate] => 1603626802 ) stdClass Object ( [from] => Sender[to] => tutorialspoint.test@gmail.com [date] => Sun, 25 Oct 2020 17:23:10 +0530 [message_id] => [size] => 4884 [uid] => 50 [msgno] => 5 [recent] => 0 [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 [draft] => 0 [udate] => 1603626831 ) stdClass Object ( [from] => Sender[to] => tutorialspoint.test@gmail.com [date] => Sun, 25 Oct 2020 17:24:25 +0530 [message_id] => [size] => 4883 [uid] => 51 [msgno] => 6 [recent] => 0 [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 [draft] => 0 [udate] => 1603626906 )
相關用法
- PHP imap_createmailbox()用法及代碼示例
- PHP imap_clearflag_full()用法及代碼示例
- PHP imap_close()用法及代碼示例
- PHP imap_create()用法及代碼示例
- PHP imap_getsubscribed()用法及代碼示例
- PHP imap_header()用法及代碼示例
- PHP imap_last_error()用法及代碼示例
- PHP imap_mutf7_to_utf8()用法及代碼示例
- PHP imap_headerinfo()用法及代碼示例
- PHP imap_lsub()用法及代碼示例
- 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_base64()用法及代碼示例
- PHP imap_listscan()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - imap_check() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。