Unable to disable imap_open error notifications in PHP

I am using PHP 5.3.5 and I am using

$this->marubox=@imap_open($this->server,$this->username,$this->password);

The @ sign should turn off the error report, but it is not, and I am sure that the error occurs on this line. I want my application to recognize the problem on its own and respond and not receive NOTICE errors, and I cannot turn off error reporting for all PHP due to my company development policy.

Without @ I get:

imap_open () [function.imap-open]: Failed to open stream {pop3.seznam.cz:110/pop3►INBOX With it I get: Notification Unknown: Authentication failed (Authentication failed) (errflg = 1)

If the login information is approved, it opens a connection and no errors occur.

I always get a NOTICE error when imap_open fails to connect and this will ruin my JSON results. How to silence him?

+5
source share
2 answers

I added

$this->marubox=@imap_open($this->server,$this->username,$this->password);
imap_errors();
imap_alerts();

and imap_errors();and imap_alerts();do the magic :)

+17
source

Two possibilities come to mind:

  • You can set error_reporting in your php.ini, ini_set or .htaccess or the like to exclude NOTICE, but since you do not want your application to handle this error, this is probably not what you need

  • Implement your own error handling. This is not so difficult to do. You define a function to eliminate errors, and then say PHP to use it instead of your own default handler.

    // define

    function myHandler ($ errno, $errstr) {}

    //- script

    set_error_handler ( "MyHandler" );

. set_error_handler. , . , /.

0

All Articles