Cek Inbox Gmail Melalui PHP

Ini dia satu lagi skrip PHP yang mungkin bakal berguna lagi suatu hari nanti.

<?
//Source by: Kevin Steffer
//http://www.linuxscope.net/articles/mailAttachmentsPHP.html
 $ServerName = "{imap.gmail.com:993/imap/ssl}INBOX"; // IMAP connection    (PORT 143)

$UserName = "username@gmail.com";
 $PassWord = "password_gmail";

$mbox = imap_open($ServerName, $UserName,$PassWord) or die("Could not open Mailbox - try again later!");

if ($hdr = imap_check($mbox)) {
 echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>";
 $msgCount = $hdr->Nmsgs;
 } else {
 echo "failed";
 }
 $MN=$msgCount;
 $overview=imap_fetch_overview($mbox,"1:$MN",0);
 $size=sizeof($overview);

echo "<table border=\"0\" cellspacing=\"0\" width=\"582\">";

for($i=$size-1;$i>=0;$i--){
 $val=$overview[$i];
 $msg=$val->msgno;
 $from=$val->from;
 $date=$val->date;
 $subj=$val->subject;
 $seen=$val->seen;

$from = ereg_replace("\"","",$from);

// MAKE DANISH DATE DISPLAY
 list($dayName,$day,$month,$year,$time) = split(" ",$date);
 $time = substr($time,0,5);
 $date = $day ." ". $month ." ". $year . " ". $time;

if ($bgColor == "#F0F0F0") {
 $bgColor = "#FFFFFF";
 } else {
 $bgColor = "#F0F0F0";
 }

if (strlen($subj) > 60) {
 $subj = substr($subj,0,59) ."...";
 }

echo "<tr bgcolor=\"$bgColor\"><td colspan=\"2\">$from</td><td colspan=\"2\">$subj</td>
 <td class=\"tblContent\" colspan=\"2\">$date</td></tr>\n";
 }

echo "</table>";
 imap_close($mbox);
 ?>

Skrip diatas hanya berfungsi untuk ngelist daftar email yang ada di inbox.

One Response to “Cek Inbox Gmail Melalui PHP”

  1. Achunk June 9, 2012 at 7:47 pm #

    Thanks, nyoba ah

Leave a Reply:

Gravatar Image

Follow

Get every new post on this blog delivered to your Inbox.

Or subscribe to the RSS feed by clicking on the counter: