About Me

My photo

one who looks outside, dreams
one who looks inside, awakens!!

Get FREE updates!! subscribe!!

Delivered by FeedBurner

Like it? Follow up!! :)

Oct 12, 2013

PHP script to read outlook email inbox

Here is a simple php code to read outlook emails. This code also contains php script to read a outlook inbox mail received from a particular email address.

Please note that the following is achieved through PHP's IMAP PROTOCOL.
Also, this is not a very secured method of doing it. The idea here is to reveal the concept.


<?php
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));

$incoming_mail_server = 'imap.gmail.com'; //This is an example incoming mail server for gmail which you can configure to your outlook, check out the manual on Supported IMAP client list

$your_email = 'me@outlookmail.com'; // your outlook email ID
$yourpassword = 'xyz' // your outlook email password

$mbox   = imap_open("{$incoming_mail_server}", $your_email , $yourpassword )   or  die("can't connect: " . imap_last_error());

$num = imap_num_msg($mbox); // read total messages in email

$MC = imap_check($mbox);

$msg=array();

// Fetch an overview for all messages in INBOX

$result = imap_fetch_overview($mbox,"$num:{$MC->Nmsgs}",0);

foreach ($result as $overview) {

echo 'Message no'.$overview->msgno. '<br/>';

     "{$overview->subject}<br/>";

       $check = imap_mailboxmsginfo($mbox);
  
   echo $check->Unread;
   
    echo $overview->subject;
    echo $overview->body;
   
//code to check and display email received from a particular Email address

    if(preg_match("/sreevathsabv@gmail.com/",$overview->from,$match)){

        $msg[$overview->msgno]=$overview->subject;

        imap_delete($mbox,$overview->msgno);

    }
    else{

        imap_delete($mbox,$overview->msgno);

    }
}
     imap_close($mbox); 

?> 



Subscribe for more cool codes , see the other links below for more codes!