PHP POP3 Mails aus Postfach auslesen

To go with PHP on the e-mails to a mailbox via POP3, I wrote this useful test scripts. So that all can not read e-mail messages with sender, Subject, Date, and e-mail body.

getEmailsImap($mailserver, $port, $user, $pass);

//open connection to mailbox, read all unread mails
function getEmailsImap($mailserver, $port, $user, $pass)
    $imap = imap_open( "{" . $mailserver . ":" . $port . "}INBOX", $user, $pass );
    if ($imap)
        echo "Connected\n";
        $check = imap_mailboxmsginfo($imap);
        echo "Date: "     . $check->Date    . "<br />\n" ;
        echo "Driver: "   . $check->Driver  . "<br />\n" ;
        echo "Unread: "   . $check->Unread  . "<br />\n" ;
        echo "Size: "     . $check->Size    . "<br />\n" ;

        $totalrows = imap_num_msg($imap);
        //iterate through all unread mails
        for ($index = 0; $index < $totalrows; $index++)
            $header = imap_header($imap, $index + 1);
             //get mail subject
             //get mail sent date
            $prettydate = date(DateTime::ISO8601 , $header->udate);
            dump( $prettydate );
            //get email author
            $email = "{$header->from[0]->mailbox}@{$header->from[0]->host}";
            dump( $email );
            //get mail body
            dump( imap_body($imap, $index + 1));
        //close connection to mailbox
        return true;
         dump("Can't connect: " . imap_last_error());
         return false;
function dump($var)
    echo "<pre><div align='left'>";
    echo "</div></pre>";
  1. Hello, Unfortunately it doesn't work for me. Or. No php script works so far for me. Tried it with gmail account and gmx account. The server might not respond and at the end of the internal server error comes (500). How did it work for you?

  2. Super script! Thank you!!! How can I but now the mails as “read” mark, so they renewed me with a query are displayed not again?