如何解决如何在 html 表中使用 imap 显示所有 gmail 电子邮件?
我正在编写 PHP 脚本,我想使用 imap 从 gmail 帐户中获取电子邮件。目前,只有看不见的电子邮件正在接收,而我需要所有电子邮件。此外,需要使用 html 表获取电子邮件并在其中显示电子邮件。
你能指导我并帮助我解决我的问题吗?我还附上了一张示例图片供您参考。
截图链接
https://imgur.com/SkYsiB3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.9.0/bootstrap-table.min.css'>
</head>
<body>
<?PHP
set_time_limit(4000);
// Connect to gmail
$imapPath = '{imap.gmail.com:993/imap/ssl}INBox';
$username = 'test@gmail.com';
$password = 'test@123';
// search and get unseen emails,function will return email ids
$emails = imap_search($inBox,'UNSEEN');
$output = '';
foreach($emails as $mail) {
$headerInfo = imap_headerinfo($inBox,$mail);
$output .= $headerInfo->subject.'<br/>';
$output .= $headerInfo->toaddress.'<br/>';
$output .= $headerInfo->date.'<br/>';
$output .= $headerInfo->fromaddress.'<br/>';
$output .= $headerInfo->reply_toaddress.'<br/>';
$emailStructure = imap_fetchstructure($inBox,$mail);
if(!isset($emailStructure->parts)) {
$output .= imap_body($inBox,$mail,FT_PEEK);
} else {
//
}
echo $output;
$output = '';
}
// colse the connection
imap_expunge($inBox);
imap_close($inBox);
?>
<table width="100%">
<thead>
<tr>
<th>Subject</th>
<th>From</th>
<th>Date</th>
<th>Message</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Subject</th>
<th>From</th>
<th>Date</th>
<th>Message</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Test</td>
<td>test@gmail.com</td>
<td>today</td>
<td>hello</td>
</tr>
</tbody>
</table>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。