从 IMAP 获取“特定”电子邮件信息

时间:2021-01-03 18:12:22

标签: php gmail imap

为了工作,我每天都会收到 Gmail 电子邮件,其中包含文本,然后是一个列出 URL 的 div 字段,我只想打印这些 URL,而不是整个邮件、我的代码和这个:

<?

/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'email';
$password = 'pass';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'UNSEEN');

/* if emails are returned, cycle through each... */
if($emails) {
    
    /* begin output var */
    $output = '';
    
    /* put the newest emails on top */
    rsort($emails);
    
    /* for every email... */
    foreach($emails as $email_number) {
        
        /* get information specific to this email */
        $overview = imap_fetch_overview($inbox,$email_number,1.2);
        $message = imap_fetchbody($inbox,$email_number,1);
        $message=imap_base64($message);

        
        /* output the email header information */
        /*$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';*/
        /*$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
        $output.= '<span class="from">'.$overview[0]->from.'</span>';*/
        /*$output.= '<span class="date">on '.$overview[0]->subject.'</span>';*/
        /*$output.= '</div>';*/
        
        /* output the email body */
        $output.= '<div class="body">'.$message.'</div> <br>';
    }
    
    echo $output;
} 

/* close the connection */
imap_close($inbox);
?>

这是电子邮件的一个例子,请有人帮帮我?

example body email image

0 个答案:

没有答案
相关问题