你好伙计们我试图使用php imap来获取邮箱消息,但我得到Network is unreachable
错误
这是我的代码
<h1>Gmail Email Inbox using PHP with IMAP</h1>
<?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', 'My correct email address here', 'My correct password here') 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><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);
}
?>
</div>
我应该从我的gmail帐户中获取邮箱,并将其显示在html中,如上面的代码所示. 让我们展示一些爱.