PHP - imap_alerts() 函数



PHP 的 IMAP 函数帮助您访问电子邮件帐户,IMAP 代表 **I**nternet **M**ail **A**ccess **P**rotocol,使用这些函数您还可以使用 NNTP、POP3 协议和本地邮箱访问方法。

imap_alerts() 函数检索从当前页面开始或自上次调用此函数以来发生的所有错误消息,并以数组的形式返回它们。

imap_binary() 函数

参数

此函数不接受任何参数。

返回值

如果成功,此函数返回一个包含所有已发生错误的数组;如果失败,则返回布尔值 false。

PHP 版本

此函数首次引入于 PHP 4 版本,并在所有后续版本中均有效。

示例

以下示例演示了 imap_alerts() 函数的使用:

<html>
   <body>
      <?php
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "[email protected]";
         $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 = "[email protected]";
         $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_function_reference.htm
广告