问题描述
我正在编写 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 (将#修改为@)