从Gmail获取邮件时,获取发件人的电子邮件ID [英] Getting e-mail ID of sender while fetching mails from Gmail

查看:232
本文介绍了从Gmail获取邮件时,获取发件人的电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Gmail获取电子邮件,我可以从中获取正文,发件人姓名等。我必须获取发件人的电子邮件地址,我无法获得。在使用imap_header抓取headerinfo后,我尝试使用一些变量名称,如fromaddress,但没有工作。
我可以获得一些帮助吗?

I am fetching email from gmail where I can fetch body, name of the sender etc. I have to get the email-id of the sender, which I am not able to get. I have tried with some variables names like fromaddress after fetchting headerinfo by imap_header but didn't work. Can I get some help regarding this ?

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?
        }
}

我用几种方法尝试过我的运气,但失败了每次...
感谢提前:)

I have tried my luck with several methods but got failed each time... Thanks in Advance :)

推荐答案

我已经做了... Hurray!

I have done it..Hurray!

这是代码: -

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

        }
}

感谢:)

这篇关于从Gmail获取邮件时,获取发件人的电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆