Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从Gmail提取邮件时获取发件人的电子邮件ID_Php_Email_Gmail - Fatal编程技术网

Php 从Gmail提取邮件时获取发件人的电子邮件ID

Php 从Gmail提取邮件时获取发件人的电子邮件ID,php,email,gmail,Php,Email,Gmail,我正在从gmail获取电子邮件,在那里我可以获取邮件的正文、发件人的姓名等。我必须获取发件人的电子邮件id,但我无法获取。在通过imap_头获取headerinfo后,我尝试了一些变量名,比如fromaddress,但没有成功。 在这方面我能得到一些帮助吗 function connect_mail(){ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = '*****@gmail.com'; $p

我正在从gmail获取电子邮件,在那里我可以获取邮件的正文、发件人的姓名等。我必须获取发件人的电子邮件id,但我无法获取。在通过imap_头获取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?
        }
}
函数连接邮件(){
$hostname='{imap.gmail.com:993/imap/ssl}收件箱';
$username='*****@gmail.com';
$password='*****';
$inbox=imap_open($hostname,$username,$password)或die(t('cannotconnecttogmail:')。imap_last_error());
$emails=imap_搜索($inbox,'ALL');
$Msgcount=计数($email);
对于($x=1;$x主题;
回音“邮件主题:.$title.”
“; $from=$overview[0]->from; 回显“发件人姓名:“.$from.”
“; //现在我必须获得发件人的邮件ID并打印出来,但如何才能获得? } }
我尝试了几种方法,但每次都失败了。。。
提前谢谢:)

我已经做了……万岁

代码如下:-

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

        }
}
函数连接邮件(){
$hostname='{imap.gmail.com:993/imap/ssl}收件箱';
$username='*****@gmail.com';
$password='*****';
$inbox=imap_open($hostname,$username,$password)或die(t('cannotconnecttogmail:')。imap_last_error());
$emails=imap_搜索($inbox,'ALL');
$Msgcount=计数($email);
对于($x=1;$x主题;
回音“邮件主题:.$title.”
“; $from=$overview[0]->from; 回显“发件人姓名:“.$from.”
“; $header=imap_headerinfo($inbox,$x); $fromaddress=$header->from[0]->mailbox.@“..$header->from[0]->host; echo“来自电子邮件地址:”.$fromaddress。; } }

谢谢:)

检查此链接,它可能会帮助您@SoumyaMohanan-发件人的电子邮件不会被提取到任何地方。谢谢:)