0

我正在从 gmail 获取电子邮件,我可以在其中获取正文、发件人姓名等。我必须获取发件人的电子邮件 ID,但我无法获得。在通过 imap_header 获取 headerinfo 后,我尝试了一些变量名称,例如 fromaddress ,但没有奏效。我能得到一些帮助吗?

function connect_mail(){

    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
    $username = '*****@gmail.com';
    $password = '*****';    
    $inbox = imap_open($hostname,$username,$password) or die(t('Cannot connect to Gmail: ' . imap_last_error()));   
    $emails = imap_search($inbox,'ALL');    
    $Msgcount = count($emails);
        for ($x = 1; $x <= $Msgcount; $x++)
        {
           $overview = imap_fetch_overview($inbox, $x);
           $title = $overview[0]->subject;
           echo "Subject of the Mail : ".$title."</br>";
           $from = $overview[0]->from;
           echo "Name of the sender : ".$from."</br>";

           //Now I have to get mail ID of senders & print it, but how?
        }
}

我已经尝试了几种方法,但每次都失败了......在此先感谢:)

4

1 回答 1

0

我做到了..万岁!

这是代码: -

function connect_mail(){

    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
    $username = '*****@gmail.com';
    $password = '*****';    
    $inbox = imap_open($hostname,$username,$password) or die(t('Cannot connect to Gmail: ' . imap_last_error()));   
    $emails = imap_search($inbox,'ALL');    
    $Msgcount = count($emails);
        for ($x = 1; $x <= $Msgcount; $x++)
        {
           $overview = imap_fetch_overview($inbox, $x);
           $title = $overview[0]->subject;
           echo "Subject of the Mail : ".$title."</br>";
           $from = $overview[0]->from;
           echo "Name of the sender : ".$from."</br>";

           $header = imap_headerinfo($inbox, $x);
           $fromaddress = $header->from[0]->mailbox . "@" . $header->from[0]->host;
           echo "From E-Mail Address : ".$fromaddress.;

        }
}

谢谢 :)

于 2012-06-15T10:13:45.703 回答