8

I am using PHP 5.3.5 and I am using

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

The @ sign should silence error reporting but it doesnt and I am sure that the error occurs on this line. I want my application to recognize the problem itself and react and get no NOTICE errors and I can't turn off error reporting for whole PHP because of my company development policy.

Without @ i am getting:

imap_open() [function.imap-open]: Couldn't open stream {pop3.seznam.cz:110/pop3}INBOX With it i get: Notice Unknown: Authentication failed (Authentication failed) (errflg=1)

If the login information is ok it opens the connection and no errors occur.

I always get NOTICE error when imap_open doesnt manage to connect and it's messing up with my JSON results. How to silence it please?

5
  • Does PHP report that line as the one that generated the notice? @ should work.
    – Belinda
    Mar 24, 2011 at 16:35
  • 1
    It would be also helpful to post what notice exactly you see. Because the @ operator should really work. Mar 24, 2011 at 16:37
  • for example: Notice Unknown: Authentication failed (Authentication failed) (errflg=1)
    – Ragnar
    Mar 24, 2011 at 17:23
  • It doesnt give me the line number but it is because of the imap open which i proved by testing
    – Ragnar
    Mar 24, 2011 at 17:24
  • if i dont use @ sign i get this instead: imap_open() [<a href='function.imap-open'>function.imap-open</a>]: Couldn't open stream {pop3.seznam.cz:110/pop3}INBOX
    – Ragnar
    Mar 24, 2011 at 17:32

2 Answers 2

25

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 :)

1
  • Worked perfectly for me. By the way, you can also assign the outputs of imap_errors() and imap_alerts() to arrays and print them out as diagnostic text.
    – xgretsch
    Nov 24, 2014 at 9:47
0

Two possibilities come to mind:

  1. You could set error_reporting in your php.ini, ini_set or .htaccess or similar so that the NOTICE is suppressed, but since you wan't your application to handle the error, this is probably not, what you need

  2. Implement your own error handling. This is not so difficult to do. You define a function for error hadnling and then tell PHP to use it instead of it's own default handler.

    //define

    function myHandler($errno, $errstr) {}

    //somewhere towards the beginning of your processing script

    set_error_handler("myHandler");

See set_error_handler for more. Also note that from the moment you register the handler, you're solely responsible. You can suppress or throw any errors you need/want.

2
  • the 1st is not what i want and the 2nd has about the same effect as the first one. I cant use anything dealing with all php errors
    – Ragnar
    Mar 24, 2011 at 17:23
  • 1
    Setting the error_reporting level has no effect on this. I just spent the better part of an hour with this, and the only way to suppress notices and warnings generated by the imap_* functions is in @Ragnar's answer. The PHP devs have done some truly ****ed up and heinous things with IMAP, making it the worst library I've ever had to deal with.
    – Sammitch
    Nov 28, 2013 at 19:03

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.