我正在从gmail获取电子邮件,我可以在其中获取正文,发件人姓名等。我必须获取发件人的电子邮件ID,但我无法获得。在获取 headerinfo 后,我尝试使用一些变量名称,例如 fromaddress imap_header但没有工作。我可以得到一些帮助吗?
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?
}
}
我尝试过几种方法的运气,但每次都失败了......提前致谢:)
我已经做到了。万岁!
这是代码:-
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.;
}
}
谢谢:)