我正在使用蓬勃发展的lib从邮箱中获取电子邮件,我尝试从浏览器登录,工作正常。当我试图通过PHP代码登录时,它给我以下错误
Array ( [0] => a0003 NO [AUTHENTICATIONFAILED] Authentication failed. )
。
<?php
private function connect() {
if ($this -> connection) {
return;
}
fCore::startErrorCapture(E_WARNING);
$this -> connection = fsockopen($this -> secure ? 'tls://' . $this -> host : $this -> host, $this -> port, $error_number, $error_string, $this -> timeout);
;
foreach (fCore::stopErrorCapture('#ssl#i') as $error) {
throw new fConnectivityException('There was an error connecting to the server. A secure connection was requested, but was not available. Try a non-secure connection instead.');
}
if (!$this -> connection) {
throw new fConnectivityException('There was an error connecting to the server');
}
stream_set_timeout($this -> connection, $this -> timeout);
if ($this -> type == 'imap') {
if (!$this -> secure && extension_loaded('openssl')) {
$response = $this -> write('CAPABILITY');
if (preg_match('#\bstarttls\b#i', $response[0])) {
$this -> write('STARTTLS');
do {
if (isset($res)) {
sleep(0.1);
}
$res = stream_socket_enable_crypto($this -> connection, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
} while ($res === 0);
}
}
$response = $this -> write('LOGIN ' . $this -> username . ' ' . $this -> password);
if (!$response || !preg_match('#^[^ ]+\s+OK#', $response[count($response) - 1])) {
throw new fValidationException('The username and password provided were not accepted for the %1$s server %2$s on port %3$s', strtoupper($this -> type), $this -> host, $this -> port);
}
$this -> write('SELECT "INBOX"');
} elseif ($this -> type == 'pop3') {
$response = $this -> read(1);
if (isset($response[0])) {
if ($response[0][0] == '-') {
throw new fConnectivityException('There was an error connecting to the POP3 server %1$s on port %2$s', $this -> host, $this -> port);
}
preg_match('#<[^@]+@[^>]+>#', $response[0], $match);
}
if (!$this -> secure && extension_loaded('openssl')) {
$response = $this -> write('STLS', 1);
if ($response[0][0] == '+') {
do {
if (isset($res)) {
sleep(0.1);
}
$res = stream_socket_enable_crypto($this -> connection, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
} while ($res === 0);
if ($res === FALSE) {
throw new fConnectivityException('Error establishing secure connection');
}
}
}
$authenticated = FALSE;
if (isset($match[0])) {
$response = $this -> write('APOP ' . $this -> username . ' ' . md5($match[0] . $this -> password), 1);
if (isset($response[0]) && $response[0][0] == '+') {
$authenticated = TRUE;
}
}
if (!$authenticated) {
$response = $this -> write('USER ' . $this -> username, 1);
if ($response[0][0] == '+') {
$response = $this -> write('PASS ' . $this -> password, 1);
if (isset($response[0][0]) && $response[0][0] == '+') {
$authenticated = TRUE;
}
}
}
if (!$authenticated) {
throw new fValidationException('The username and password provided were not accepted for the %1$s server %2$s on port %3$s', strtoupper($this -> type), $this -> host, $this -> port);
}
}
}
?>
我正在使用正确的凭据。当我从其他服务器使用时,相同的代码似乎可以获取电子邮件。无法确定问题,请帮助