PHP IMAP Script to Read Outlook Email Inbox

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

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

  error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
  $incoming_mail_server = ''; 
  //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 below.
  $your_email = ''; // 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);
  // 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/>';
           $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

Here is a list of Supported IMAP client list

Let us know through comments if it was helpful and please share with others.


Recommended Articles

1 Comment

  1. Good write-up, I am regular visitor of one’s web site, maintain up the nice operate, and It’s going to be a regular visitor for a long time.

Leave a Reply

Pin It on Pinterest