Php-imap: Kerberos error at connexion

Created on 16 May 2013  ·  3Comments  ·  Source: barbushin/php-imap

PHP displays notice when IMAP server requires Kerberos tickets, even if it fallbacks to classical credentials (login/password).

PHP Notice:  Unknown: Kerberos error: No credentials cache found (try running kinit) for imap.example.com (errflg=1) in Unknown on line 0

Most helpful comment

To fix my issue, it could be possible to disable GSSAPI authentication when performing the connexion to the server:

$imapStream = @imap_open($this->imapPath, $this->login, $this->password, 0, 0, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));

All 3 comments

To fix my issue, it could be possible to disable GSSAPI authentication when performing the connexion to the server:

$imapStream = @imap_open($this->imapPath, $this->login, $this->password, 0, 0, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));

Thank you @tchemineau , 7 years later, you saved my ass from I don't know how many much more hours!!! 🥳

You can set these parameters using the function setConnectionArgs($options = 0, $retriesNum = 0, $params = null):

<?php

    require_once __DIR__ . '/../vendor/autoload.php';
    use PhpImap\Mailbox;
    use PhpImap\Exceptions\ConnectionException;
    use PhpImap\Exceptions\InvalidParameterException;

    $mailbox = new Mailbox(
        '{imap.gmail.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder
        '[email protected]', // Username for the before configured mailbox
        '*********', // Password for the before configured username
        __DIR__, // Directory, where attachments will be saved (optional)
        'US-ASCII' // Server encoding (optional)    
    );

    try {
        $mailbox->setConnectionArgs(0, 0, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));
    } catch(InvalidParameterException $ex) {
        die("Failed to set connection arguments: " . $ex->getMessage());
    }

    try {
        $mail_ids = $mailbox->searchMailbox('UNSEEN');
    } catch(ConnectionException $ex) {
        die("IMAP connection failed: " . $ex->getMessage());
    } catch (Exception $ex) {
        die("An error occured: " . $ex->getMessage());
    }

    foreach ($mail_ids as $mail_id) { ... }
Was this page helpful?
0 / 5 - 0 ratings