-1
I’m making a code to read emails through IMAP, only I’m finding a problem to show the sender’s email. instead of showing the email it is showing the name. already tried other functions but also did not work put the
'remetente: '.$header->fromaddress;.
more does not work.
Would anyone know the reason for this mistake ?
below follows the example
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$status = imap_status($inbox, "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX", SA_ALL);
if ($status) {
echo "Total Messages: " . $status->messages . "<br />\n";
echo "Recentes: " . $status->recent . "<br />\n";
echo "Não Lidas: " . $nlidas = $status->unseen . "<br />\n";
echo "Proximo Id: " . $status->uidnext . "<br />\n";
echo "Vizualizações:" . $status->uidvalidity . "<br />\n";
} else {
echo "imap_status failed: " . imap_last_error() . "\n";
}
echo '<hr>';
$emails = imap_search($inbox,'ALL');
if($emails) {
$output = '';
rsort($emails);
$i = 0;
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,"1.1");
$header = imap_header($inbox,$email_number,"1");
echo 'Id: '. $id = $overview[0]->uid;
echo '<br>';
echo 'Assunto: '. $assunto = iconv_mime_decode($overview[0]->subject);
echo '<br>';
echo 'De: '. $de =$overview[0]->from;
echo '<br>';
echo 'Para: '. $para =$overview[0]->to;
echo '<br>';
echo 'Data:'. $data =$overview[0]->date;
echo '<br>';
echo 'remetente: '.$header->fromaddress;
echo '<br>';
if (++$i == 10) break;
echo '<br>';
echo '<br>';
}
}
imap_close($inbox);