當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP imap_alerts()用法及代碼示例



PHP-IMAP 函數可幫助您訪問電子郵件帳戶,IMAP 代表I互聯網M艾爾A訪問權限Protocol 使用這些函數您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

這個imap_alerts()函數檢索從當前頁麵開始或自上次調用此函數以來發生的所有錯誤消息,並以數組的形式返回它們。

imap_binary()function notranslate"> imap_alerts();

參數

該函數不接受任何參數。

返回值

此函數返回一個包含所有發生錯誤的數組,如果成功,則返回布爾值 false 。

PHP版本

這個函數最初是在 PHP 版本 4 中引入的,並且適用於所有後續版本。

示例

下麵的例子演示了imap_alerts()函數 -

<html>
   <body>
      <?php
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "wrong_password";
         $mailbox = imap_open($url, $id, $pwd);
         print("<br>");
         if ( $mailbox === false ) {
            exit ("Alerts:<br>" . $alerts = imap_alerts() ."\n");
         } else {
            print("Connection established....");
         }
      ?>
   </body>
</html>

輸出

這會生成以下輸出 -

Connection established....
List of mailboxes:
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX
Alerts:

Notice:Unknown:[ALREADYEXISTS] Duplicate folder name INBOX.test_mail1 (Failure) (errflg=2) in Unknown on line 0

Notice:Unknown:[ALREADYEXISTS] Duplicate folder name INBOX.test_mail2 (Failure) (errflg=2) in Unknown on line 0

示例

以下是此函數的另一個示例 -

<html>
   <body>
      <?php
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $mailbox = imap_open($url, $id, $pwd);
         print("Connection established....");
         print("<br>");

         //Creating mailboxes
         $newmailbox1 = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail1";
         $newmailbox2 = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX.test_mail2";            
         $res = imap_createmailbox($mailbox, imap_utf7_encode($newmailbox1));
         $res = imap_createmailbox($mailbox, imap_utf7_encode($newmailbox2));

         //Retrieving the contents of mail boxes
         print("List of mailboxes:");
         print("<br>");
         $list = imap_getmailboxes($mailbox, $url, "*");
		
         foreach ($list as $key => $val) {
            print_r($val->name);
            print("<br>");
            exit ("Alerts:<br>" . $alerts = imap_alerts() ."\n");      
         }
      ?>
   </body>
</html>

輸出

這將生成以下輸出 -

Warning:imap_open():Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in C:\Apache24\htdocs\examples\demo2.html on line 7

Alerts:

Notice:Unknown:[AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0

Notice:Unknown:[AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0

Notice:Unknown:[AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0

Notice:Unknown:Too many login failures (errflg=2) in Unknown on line 0

相關用法


注:本文由純淨天空篩選整理自 PHP - imap_alerts() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。