مشاهده ایمیلهای خوانده نشده GMail
با کمی تغییر میتونید مدلهای مختلفی از این کد استفاده کنید. مثلاً ایمیلهای یک روز خاص، ارسال شده ها، ایمیلهایی که بهشون جواب دادین و...
کد HTML:
<!doctype html>
<html>
<head>
<title>Read GMail with IMAP</title>
<meta charset="utf-8"/>
<script src="jqmin.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('div.body').slideUp('slow');
$('div.toggler').click(function() {
$(this).addClass('read').removeClass('unread');
$(this).next('div.body').slideToggle('slow');
});
});
</script>
<style type="text/css">
div.toggler {
border: 1px solid #ccc;
cursor: pointer;
padding: 10px 32px;
}
div.toggler .subject {
font-weight: bold;
}
div.read {
color: #666;
}
div.toggler .from, div.toggler .date {
font-style: italic;
font-size: 12px;
}
div.body {
border: solid thin #7f7f7f;
padding: 10px 20px;
}
</style>
</head>
<body>
<?php
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'your_account@gmail.com';
$password = 'your_password';
/* try to connect */
$inbox = imap_open($hostname, $username, $password, OP_READONLY) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox, 'UNSEEN');
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox, $email_number, 0);
$message = imap_utf8(imap_fetchbody($inbox, $email_number, 2));
/* output the email header information */
$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'.PHP_EOL;
$output.= '<span class="subject">'.imap_utf8($overview[0]->subject).'</span> ';
$output.= '<span class="from">'.imap_utf8($overview[0]->from).'</span> ';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>'.PHP_EOL;
/* output the email body */
$output.= '<div class="body">'.$message.'</div>'.PHP_EOL;
}
echo $output;
}
/* close the connection */
imap_close($inbox);
?>
</body>
</html>
امیدوارم که این کد هم به دردتون بخوره.
موفق باشید.