PHP imap_open() => [AUTHENTICATIONFAILED]

10,911

Because the web server and mail server were running on the same server, I managed to connect with the server IP address:

$mbox = imap_open('{127.0.0.1:993/imap/ssl/novalidate-cert}INBOX', '[email protected]', 'password');
Share:
10,911
Daniel Iancu
Author by

Daniel Iancu

Updated on June 04, 2022

Comments

  • Daniel Iancu
    Daniel Iancu about 2 years

    I'm trying to set up an IMAP connection to a mail server, the problem is it fails with message:

    array(4) {
      [0]=> string(81) "Retrying PLAIN authentication after [AUTHENTICATIONFAILED] Authentication failed."
      [1]=> string(81) "Retrying PLAIN authentication after [AUTHENTICATIONFAILED] Authentication failed."
      [2]=> string(82) "Can not authenticate to IMAP server: [AUTHENTICATIONFAILED] Authentication failed."
      [3]=> string(49) "[CLOSED] IMAP connection broken (server response)"
    }
    

    The code that I use to open the connection is:

    $mbox = imap_open('{server.test.com:993/imap/ssl}INBOX', '[email protected]', 'password');
    

    I have tested the same syntax for my Gmail account and it works fine. I can connect to the server.test.com and also authenticate using thunderbird (IMAP - SSL - 993), so it's not really the mail server having a problem.

    I've searched through Stack Overflow for this issue, but I haven't managed to solve it, below are all the solutions I have tried so far:

    1. $mbox = imap_open('{server.test.com:993/imap/ssl}INBOX', '[email protected]', 'password', null, 1, array('DISABLE_AUTHENTICATOR' => 'PLAIN'));
    2. $mbox = imap_open('{server.test.com:995/pop3/ssl}INBOX', '[email protected]', 'password');
    3. $mbox = imap_open('{server.test.com:993/imap/ssl/novalidate-cert}INBOX', '[email protected]', 'password'); (The cert is valid)
    4. $mbox = imap_open('{server.test.com:993/pop3/ssl/novalidate-cert}INBOX', '[email protected]', 'password'); (The cert is valid)
    5. $mbox = imap_open('{server.test.com:993/imap}INBOX', '[email protected]', 'password');
    6. $mbox = imap_open('{server.test.com:993/pop3}INBOX', '[email protected]', 'password');
    7. $mbox = imap_open('{server.test.com:993}INBOX', '[email protected]', 'password');

    Any idea from where the problem can come from? I'll also post all the error messages I got for all the solutions mentioned above and also the mail server and php logs later.

    Note: To represent the errors I'm using:

    var_dump(imap_errors());