0

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, ...)

Passi
  • 3
  • 2
  • 1
    _“I want to build an authentication system for a website using IMAP”_ – and you think this is a good idea because …? – CBroe Feb 14 '17 at 10:58
  • @CBroe I absolutely don't think it's a good idea! But I don't know how to check if the user has provided valid credentials (username, password) besides IMAP. I don't have acess to the email server or the server on wich the user data is stored... But the users should be able to login with the same credentials like they would logging in to their school email (username@certaindomain.com and their password). Do you have any other ideas how to achieve this? I don't have any clue ... besides IMAP. I know it's an terrible approach! – Passi Feb 14 '17 at 11:14

1 Answers1

0

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

Community
  • 1
  • 1
Mateusz Marchel
  • 772
  • 4
  • 14