Search code examples
phplaravelimaplaravel-5.3

imap_open custom error callback


I want to build an authentication system for a website using IMAP. Users should be able to log in with the same credentials as the email account.

Everthing works fine, except if the input data is wrong or didn't match with the email account credentials. If so, there is obviously an error...

imap_open(): Couldn't open stream {domain.com:993/imap/ssl}INBOX

Is there any way to set an custom callback if the imap_open() fails? (Like redirect back with error message, ...)


Solution

  • This is warning level message so you should be able to use error handler, for example:

    set_error_handler(function() { /* this will be executed on error */ });
    imap_open();
    restore_error_handler();
    

    Here is similar question: https://stackoverflow.com/a/1241751/3470670

    Here you can find complete documentation about setting custom error handler http://php.net/manual/en/function.set-error-handler.php