Jump to content

Fast way to extract email body using IMAP?


sloth456

Recommended Posts

Hi guys,

 

I have written a script that opens up my gmail messages via IMAP stores them in an array.  However, I have thousands of emails, so this is taking forever.  Is there a faster way of doing this?

 

Here's my code

 

<?php
//lets get those emails

/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'info@***********.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) {
  

  /* for every email... */
  foreach($emails as $email_number) {
    
    $message = imap_fetchbody($inbox,$email_number,2);
  }
  
} 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.