简体   繁体   中英

How to get every subject of email with php imap?

<?php
$hostname = '{imap.gmail.com:993/imap/ssl}';
$username = 'xxx@gmail.com';
$password = 'pass';
$inbox = imap_open($hostname,$username,$password);
$nums=imap_num_msg($inbox);
echo  $nums;
for ($i=1;$i<=$nums;$i++){
    $headers = imap_fetchheader($inbox, $i);
    echo  $headers ;}
imap_close($inboxi);
?>

With this code I can get the number of all emails in my gmail box. But it can't print every subject of email in header info. How to get it?

imap_headerinfo()imap_header()将帮助您了解每封电子邮件的主题

This is what I do:

$overview = imap_fetch_overview($inbox, $i, 0);
echo $overview[0]->subject . "<BR>";

I think it is easier than using imap_fetchheader.

Also, you have an extra 'i' in the last $inbox .

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