Advertisement
Guest User

Untitled

a guest
May 7th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2. $server = "mail.site.com:995/pop3/ssl/novalidate-cert";
  3. $folder = "INBOX";
  4. $username = "dev+site.com";
  5. $password= "dev";
  6. if( !$conn = @imap_open( "{".$server."}$folder", $username, $password ) ) {
  7.     foreach( imap_errors() as $error ) {
  8.         echo "$error <br />";
  9.     }
  10. } else {
  11.     // fetch the messages
  12.     $msgCount = imap_num_msg( $conn );
  13.     if( $msgCount == 0 ) {
  14.         echo "<h1>Mailbox is empty</h1>";
  15.     } else {
  16.         for( $i = 1; $i <= $msgCount; ++$i ) {
  17.             echo "<b>Message $i of $msgCount</b><br />";
  18.             $header = imap_header( $conn, $i );
  19.             $from = $header->from[0]->mailbox; // just the name, no hostname
  20.             $subject = $header->subject;
  21.             $body = explode( "\n", imap_body( $conn, $i ) ); // first line of the body
  22.             echo "From: $from <br />Subject: $subject <br />Message: {$body[0]}<br /><br />";
  23.         }
  24.     }
  25.     imap_close( $conn );
  26. }
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement