I'm reading e-mails from a mailbox on my domain. It's all ok, i'm getting overview "from" and "subject", then body content... all in UTF-8 except Gmail and yahoo mails. I did this function:
function newmail($username, $password){
/* connect to server */
$server = "mail.domain.com";
$port = "993";
$type = "imap";
$secure = "ssl";
$options = "novalidate-cert";
$hostname = "{".$server."/".$type."/".$options."}INBOX";
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to inbox: '.$username.' on '.$server.' ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails) {
$subjects = '';
$senders = '';
$bodys = '';
$dates = '';
/* 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 = iconv("ISO-8859-1", "UTF-8", quoted_printable_decode(imap_fetchbody($inbox, $email_number, 1)));
$senders .= iconv("ISO-8859-1", "UTF-8", quoted_printable_decode($overview[0]->from))." ## ";
$subjects .= iconv("ISO-8859-1", "UTF-8", quoted_printable_decode($overview[0]->subject))." ## ";
$bodys .= $message." ## ";
$dates .= $overview[0]->date." ## ";
}
}
/* close the connection */
imap_close($inbox);
//return different parts to explode
$emails = array(
'sender' => $senders,
'subject' => $subjects,
'body' => $bodys,
'date' => $dates
);
return $emails;
}
I'm doing this way cause i want to make something when read the body depending of subject etc.
The issue happen when i send an email from a gmail or yahoo account (i've not tried with outlook, only with 3/4 different domain mailing servers, gmail and yahoo). It makes appear some glitches like:
=?UTF-8?Q?Joël_Bo?=
i think i'm parsing well to UTF-8, otherwise it hadn't been working on other emails. The glitch i pasted...i copied it from overview ("from") part, and i have more glitch on body too.
Any idea?
- PD: i dont want to use php pear, zend or others, i want to make it with pure php. Don't mean to insert third party scripts on my one-
Thanks!