user3669523
user3669523

Reputation: 69

Retrieving email: Gmail-PHP-IMAP

I am using IMAP Protocol to fetch my Inbox emails to a small PHP app i am writing.

I am getting this Error message:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13055589 bytes) in /home/admin/public_html/boltmail/inbox.php on line 56

But if i look at this error it does not make a lot of sense.....It says the allowed memory size is 33Mb and it only needed 13Mb to allocate the data.....

PHP Code:

    <?php

/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'tomasz@*****.com';
$password = '*****';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'ALL');

/* if emails are returned, cycle through each... */
if($emails) {

    /* begin output var */
    $output = '';

    /* put the newest emails on top */
    rsort($emails);

    /* for every email... */
    foreach($emails as $email_number) {

        /* get information specific to this email */
        $overview = imap_fetch_overview($inbox,$email_number,0);
        $message = imap_fetchbody($inbox,$email_number,2);

        /* output the email header information */
        $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 the email body */
        $output.= '<div class="body">'.$message.'</div>';
    }

    echo $output;
}

/* close the connection */
imap_close($inbox);




?>

Besides I am using this tutorial to import my gmail emails: Tutorial Link

Upvotes: 0

Views: 163

Answers (1)

giorgio
giorgio

Reputation: 10202

The error message may be confusing, but it does make sense: php tried to allocate 13 mb, on top of the 32 mb allowed. So you basically would need at least 45 mb. So first of all, increase the memory limit, that should this problem.

Upvotes: 1

Related Questions