[wd_asp elements=’search’ ratio=’100%’ id=1]

Imap – Get content of email – PHP

12th February 2014

Php - Email

php codehaven

The read only part will not let the imap mark the email as read, meaning it will not move the email only copy not to another folder

$result in your mailbox

";
if($emails){
$limit = 1000;
//loop each email retrieve.
foreach($emails as $email_number){
//fetch the email over view... if you want to see the overview of the email.(OPTIONAL)
$overview = imap_fetch_overview($inbox,$email_number,0);
//fetch the email content body... This will show only the email content.
$message = imap_fetchbody($inbox, $email_number,"1");
//set the message format to UTF-8
$message = imap_utf8($message);
$message = strip_tags($message);
//add break in each line of the image.
$message = nl2br($message);
//Now, you can either echo the image or USE for for other functions like saving in database.
echo "


".$message;
// increment limit
$limit++;

//if limit is true. Break the loop and exit.
if($limit === 1)
break;
}
}
imap_close($inbox);
?>