这是我列出来自 Gmail 的电子邮件的 PHP 代码,我还在 php.ini 和 gmail 中启用了 IMAP。但我不断收到以下错误,我做错了什么?
///
警告:imap_open():无法在第 62 行打开 C:\xampp7\htdocs\inbox\gmail\index.php 中的流 {imap.gmail.com:993/imap/ssl}INBOX 无法连接到 Gmail:太多登录失败通知:未知:[AUTHENTICATIONFAILED] 第 0 行未知中的无效凭据(失败)(errflg=1)
注意:未知:[AUTHENTICATIONFAILED] 第 0 行未知中的无效凭据(失败)(errflg=1)
注意:未知:[AUTHENTICATIONFAILED] 第 0 行未知中的无效凭据(失败)(errflg=1)
注意:未知:在第 0 行的未知中登录失败太多(errflg=2) ///
<?php
if (! function_exists('imap_open')) {
echo "IMAP is not configured.";
exit();
} else {
?>
<div id="listData" class="list-form-container">
<?php
/* Connecting Gmail server with IMAP */
$connection = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', 'gmail username', 'password') or die('Cannot connect to Gmail: ' . imap_last_error());
/* Search Emails having the specified keyword in the email subject */
$emailData = imap_search($connection, 'SUBJECT "Article "');
if (! empty($emailData)) {
?>
<table>
<?php
foreach ($emailData as $emailIdent) {
$overview = imap_fetch_overview($connection, $emailIdent, 0);
$message = imap_fetchbody($connection, $emailIdent, '1.1');
$messageExcerpt = substr($message, 0, 150);
$partialMessage = trim(quoted_printable_decode($messageExcerpt));
$date = date("d F, Y", strtotime($overview[0]->date));
?>
<tr>
<td style="width:15%;"><span class="column"><?php echo $overview[0]->from; ?></span></td>
<td class="content-div"><span class="column"><?php echo $overview[0]->subject; ?> - <?php echo $partialMessage; ?></span><span class="date"><?php echo $date; ?></span></td>
</tr>
<?php
} // End foreach
?>
</table>
<?php
} // end if
imap_close($connection);
}
?>