PHP 在 IMAP 服务器需要 Kerberos 票证时显示通知,即使它回退到经典凭据(登录名/密码)。
PHP Notice: Unknown: Kerberos error: No credentials cache found (try running kinit) for imap.example.com (errflg=1) in Unknown on line 0
为了解决我的问题,可以在执行与服务器的连接时禁用 GSSAPI 身份验证:
$imapStream = @imap_open($this->imapPath, $this->login, $this->password, 0, 0, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));
谢谢@tchemineau ,7 年后,你救了我的屁股,我不知道还有多少小时!!! 🥳
您可以使用函数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) { ... }
最有用的评论
为了解决我的问题,可以在执行与服务器的连接时禁用 GSSAPI 身份验证: