简体   繁体   中英

How to fetch email, subject and name separately using imap_headers() in php?

I'm trying to fetch the email address from email account. Following script is working fine for me.

$mbox = imap_open("{mail.b******n.com:143/novalidate-cert}", "myEmail@b******n.com", "myPassWord");
$headers = imap_headers($mbox);
print_r($headers);
if ($headers == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($headers as $val) {
        echo $val . "<br />\n";
    }
}
imap_close($mbox);

Above code is returning date, email address ( if no name ) and subject.

Example : [1118] => 1119)13-May-2016 Facebook You have more friends on (16765 chars)

[1192] =>       1193)25-May-2016 John  Re: B****c Website Feedba (27152 chars)

[1224] =>       1225)30-May-2016 k****n@b***n.c DSR is not submitted prop (83005 chars)

Means above code returning the email if email has no From: Name . So is there any way to fetch the email addresses only? I would like to appreciate if someone guide me regarding this. Thank You

You might want to fetch message information with imap_fetch_overview :

$MC = imap_check($mbox);

$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
foreach ($result as $overview) {
    echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from}
    {$overview->subject}\n";
}
imap_close($mbox);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM