
<form method="POST" action="">
    <input type="text" name="hostname" size="50" value="{imap-mail.outlook.com:993/imap/ssl}INBOX"/><br><br>
    <input type="text" name="email" size="50" value="<?php echo $_POST['email'] ?>"/><br><br>
    <input type="password" name="password" size="50" value="<?php echo $_POST['password'] ?>"/><br><br>
    <input type="submit" value="Search" name=""/><br>
    
</form>


<?php
    
    
    if(isset($_POST['hostname']) && isset($_POST['email']) && isset($_POST['password'])){
        $hostname = $_POST['hostname'];
        $username = $_POST['email'];
        $password = $_POST['password'];
        $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to MAILBOX: ' . imap_last_error());
        $emails = imap_search($inbox,'ALL');
        echo '<textarea rows="40" style="width: 100%;">';
        if($emails) {
                $output = '';
                rsort($emails);
               
                foreach($emails as $email_number) 
                {
                        $overview   =   imap_fetch_overview($inbox,$email_number,0);
                        //echo imap_fetchbody($inbox,$email_number,1);
                        $message    =   imap_fetchbody($inbox,$email_number,1);
                        $message    =   preg_replace('/\s+/', ' ', trim($message));
                        echo $message."\n";
                        //$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
                         //$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
                        //$output.= '<span class="from">'.$overview[0]->from.'</span>';
                        //$output.= '<span class="date">on '.$overview[0]->date.'</span>';
                        //$output.= '</div>';
                        //$output.= '<div class="body">'.$message.'</div>';
                }
                

                //echo $output;
        } 
        imap_close($inbox);
    }
    
     
        //echo $message;
     echo '</textarea>';

