How to download email using PHP

I am trying to write a very simple email web client from scratch using the standard PHP library. I will be honest; I'm not quite sure what I'm doing, so this is what I hacked together to learn trial and error. However, I continue to timeout no matter what I try. Any advice? I know that the expected result will not look beautiful, but, as I said, this is just for trial and error.

<?php

$stream = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', '<email_removed>', '<password_removed>') or
    die('Cannot connect to server: ' . imap_last_error());

$date = date('d M Y', strtotime('-1 month'));
if ($emails = imap_search($stream, "SINCE \"$date\"")) {
    rsort($emails);

    foreach ($emails as $email_number) {
        echo imap_fetchbody($stream, $email_number, 2);
    }
}

imap_close($stream);

?>

I get the output as follows.

Warning : imap_open () [function.imap-open]: Could not open stream {imap.gmail.com:993/imap/ssl►INBOX on line 3 Could not connect to server: Could not connect to gmail-imap.l.google .com, 993: network unavailable

: : gmail-imap.l.google.com, 993: (errflg = 1) Unknown 0

: : gmail-imap.l.google.com, 993: (errflg = 1) Unknown 0

: : gmail-imap.l.google.com, 993: (errflg = 2) Unknown 0

+5
1

(HostMonster) , .:/

+3

All Articles