/* Create gmail connection */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'user@gmail.com';
$password = 'pass';
/* Fetch emails */
/* If emails are returned, cycle through each... */
if ($emails) {
$output = '';
/* Make the newest emails on top */
/* For each email... */
foreach ($emails as $email_number) {
//показва емайл адреса
$fromaddr = $headerInfo->from[0]->mailbox . "@" . $headerInfo->from[0]->host;
/* get mesage body */
if (isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) { $part = $structure->parts[1];
if ($part->encoding == 3) {
} else if ($part->encoding == 1) {
} else {
}
}
/* get information specific to this email */
/*
// If attachment found use this one
// $message = imap_qprint(imap_fetchbody($inbox,$email_number,"1.2"));
*/
$output .= 'Subject: ' . imap_utf8($overview[0]->subject) . '<br />'; $output .= 'Body: ' . $message . '<br />';
$output .= 'From: ' . imap_utf8($overview[0]->from) . '<br />'; $output .= 'Имeйл: ' .$fromaddr. '<br /><hr />';
//$output .= 'CC: ' . $headerInfo->ccaddress . '<br />'; -
// Attachments
if (isset($structure->parts) && count($structure->parts)) { for ($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false,
'filename' => '',
'name' => '',
'attachment' => ''
);
if ($structure->parts[$i]->ifdparameters) {
foreach ($structure->parts[$i]->dparameters as $object) {
if (strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true;
$attachments[$i]['filename'] = $object->value;
}
}
}
if ($structure->parts[$i]->ifparameters) {
foreach ($structure->parts[$i]->parameters as $object) {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['name'] = $object->value;
}
}
}
if ($attachments[$i]['is_attachment']) {
$attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i + 1);
/* 3 = BASE64 encoding */
if ($structure->parts[$i]->encoding == 3) {
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); }
/* 4 = QUOTED-PRINTABLE encoding */ elseif ($structure->parts[$i]->encoding == 4) {
}
}
}
}
foreach ($attachments as $attachment) {
if ($attachment['is_attachment'] == 1) {
$filename = $attachment['name'];
$filename = $attachment['filename'];
$file_path = 'upload/'; // Upload folder
$fp = fopen($file_path . $filename, "w+"); fwrite($fp, $attachment['attachment']); }
}
// Attachments
/* change the status */
}
echo $output;
}
/* close the connection */