请我需要一个完整的代码php或html来从IMAP获取电子邮件信息 例如,我给它电子邮件和密码& IMAP服务器 我收到主题或电子邮件。 谢谢你的帮助
我正在尝试
$server = '{imap.gmail.com:993/ssl}';
$user = 'myUser';
$password = 'myPassword';
$connection = imap_open($server, $user, $password);
$count = imap_num_msg($connection);
echo $
但没有结果
答案 0 :(得分:0)
<table>
<tbody>
<?php
/* connect to gmail */
$hostname = '{domail.com:143/novalidate-cert}INBOX'; // domain.com instead of your site name
$username = 'example@domain.com'; //here your mail id
$password = 'password'; //here your password
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,1.2);
$structure = imap_fetchstructure($inbox, $email_number);
$output.= '<tr class="'.($overview[0]->seen ? 'read' : 'unread').'">
<td class="mail-select">
<div class="checkbox checkbox-primary m-r-15">
<input id="checkbox1" type="checkbox">
<label for="checkbox1"></label>
</div>
<i class="fa fa-star m-r-15 text-muted"></i>
<i class="fa fa-circle m-l-5 text-warning"></i>
</td>';
$output.= '<td>
<a href="#" class="email-name">'.$overview[0]->from.'</a>
</td>';
$output.= '<td>
<a href="#" class="email-msg">'.$overview[0]->subject.'</a>
</td>
<td style="width: 20px;">
<i class="fa fa-paperclip"></i>
</td>';
$output.= '<td class="text-right">';
$mail_datetime=$overview[0]->date;
$cur_date=date('d-M-Y');
$mail_date=date('d-M-Y', strtotime($mail_datetime));
$mail_time=date('h:i A', strtotime($mail_datetime));
if($cur_date==$mail_date)
{
$output.=$mail_time;
}
else
{
$output.=$mail_date;
}
$output.= '</td>
</tr>';
}
echo $output;
}
/* close the connection */
imap_close($inbox);
?>
</tbody>
</table>