Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2003, 11:59 AM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default imap streaming error identification...

I have make a few test using this script

<?php
$stream = @imap_open("{localhost:143}", "chira", abc);

if (!$stream) {
        echo "Could not log you onto the system!";
} else {
        echo "success";
        imap_close($stream);
}

?>

the first time, i use the wrong password, and i got
this error...

Could not log you onto the system!
Notice: (null)(): LOGIN failed (errflg=1) in Unknown on line 0

Notice: (null)(): LOGIN failed (errflg=1) in Unknown on line 0

Notice: (null)(): LOGIN failed (errflg=1) in Unknown on line 0

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


and the second time, i used the wrong address, to return this address

Could not log you onto the system!
Notice: (null)(): Host not found (#11001): localhos (errflg=2) in Unknown on line 0


the third time, i changed the port number to get this error

Could not log you onto the system!
Notice: (null)(): Can't connect to vandoria-vc-a,14: Refused (10061) (errflg=2) in Unknown on line 0


how in the world can i work around with the error, so i make
a pre-formatted error page, instead of using the internal
error defined by php?

in my idea is, find what the exactly error is, and forward
user to the error page (by passing some pointer argument)



 
Old November 28th, 2003, 04:41 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

There are two functions in the imap library that return errors.
imap_errors() and imap_alerts()

http://www.php.net/imap_errors
http://www.php.net/imap_alerts

Each function should be called after calling on an imap resource. Each function also returns an array if there are any errors or alerts found.

Below is an example of a function that calls on these.

Code:
<?php
        function mailbox_errors()
        {                            
            $errors = imap_errors();
            $alerts = imap_alerts();

            if (is_array($alerts))
            {                                
                foreach ($alerts as $alert)
                {
                    echo $alert;                
                }    
            }

            if (is_array($errors))
            {                    
                foreach($errors as $error)
                {                        
                    echo $error;
                }                
            }        

        }

?>
: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old December 5th, 2003, 03:08 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Also - for clarification.. I hate to dig in on an already old thread but I'm actually wrong in saying that you *must* call on imap_errors() and imap_alerts() after *every* call to an imap resource.. in fact, if I understand the documentation correctly, these may also be called at the very end of a script's execution and whatever is printed out will be whatever alerts and errors have accumalated during the script's execution. And once called all of the errors accumalated are discarded. It would be safe to say that these would need to be called on before a call to imap_close().. which would likely destroy any errors still sitting around in memory.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old December 5th, 2003, 03:18 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Another thing that I forgot to mention.. one small nuance with the IMAP library is some function calls generate Notice level errors when there isn't *really* an error... for instance.. a call to imap_open() will generate a Notice level error when the mailbox is empty, but not one when the mailbox contains messages. A bit annoying, as an empty mailbox isn't an *error* state. But a call to imap_errors() clears this Notice level error.. essentially it takes the error out of the general PHP error scope and places it as an indice in the array generated by imap_errors(). Very strange!

This is actually mentioned in the user-contributed notes for the imap_open function:
Quote:
quote:From: http://www.php.net/imap_open


Using @imap_open to avoid the "mailbox is empty" error, DOES NOT WORK! This is because the error is actually reported at the END of the script, not during the imap_open call. Just call imap_errors() after imap_open() and it will be cleared. It took a while to figure out what was happening here.

Really, an empty mailbox is a normal state, not an error state. This should not be reported at all.
: )
Rich



:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
About Anonymous Identification Lee Dumond BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 15 December 14th, 2008 05:12 PM
Dropdownlist Items Identification msbsam ASP.NET 2.0 Professional 1 August 18th, 2008 12:50 PM
Newbie help with imap on wamp with joomla MMS blog 123newbie PHP How-To 1 April 28th, 2007 04:06 AM
Imap _open() error vibinkrish PHP How-To 0 March 1st, 2006 05:31 AM
PHP IMAP implementation to process attachments azimu Pro PHP 17 December 7th, 2004 11:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.