IMAP does not show sender email

Asked

Viewed 71 times

-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);

inserir a descrição da imagem aqui

1 answer

1


Hello, subistitui this code:

echo  'De: '. $de =$overview[0]->from;
echo '<br>';

by this code:

echo  'De: '. $de =$overview[0]->from;
$e=$header->from[0];
echo '['.$e->mailbox.'@'.$e->host.']';
echo '<br>';

For the $overview->from; only contains the intelligible name, not the sender’s email. If you want to check everything that each returned object has, use: print_r($objeto); or print_r($overview[0]->from); that PHP prints an array with all the properties that each object, array or variable has.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.