簡體   English   中英

從IMAP獲取電子郵件信息

[英]Get email information from IMAP

請我需要完整的代碼php或html才能從IMAP獲得電子郵件信息,例如,我給它提供電子郵件和密碼以及IMAP服務器,並且我接收主題或來自電子郵件。 謝謝您的幫助

我正在努力

$server = '{imap.gmail.com:993/ssl}';
$user = 'myUser';
$password = 'myPassword';
$connection = imap_open($server, $user, $password);
$count = imap_num_msg($connection);
echo $

但沒有結果

<table>
 <tbody>
    <?php
    /* connect to gmail */
    $hostname = '{domail.com:143/novalidate-cert}INBOX'; // domain.com instead of your site name 
    $username = 'example@domain.com'; //here your mail id
    $password = 'password'; //here your password

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

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

    /* 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,0);

    $message = imap_fetchbody($inbox,$email_number,1.2);
    $structure = imap_fetchstructure($inbox, $email_number);

    $output.= '<tr class="'.($overview[0]->seen ? 'read' : 'unread').'">
    <td class="mail-select">
    <div class="checkbox checkbox-primary m-r-15">
    <input id="checkbox1" type="checkbox">
    <label for="checkbox1"></label>
    </div>

    <i class="fa fa-star m-r-15 text-muted"></i>

    <i class="fa fa-circle m-l-5 text-warning"></i>
    </td>';

    $output.= '<td>
    <a href="#" class="email-name">'.$overview[0]->from.'</a>
    </td>';

    $output.= '<td>
    <a href="#" class="email-msg">'.$overview[0]->subject.'</a>
    </td>
    <td style="width: 20px;">
    <i class="fa fa-paperclip"></i>
    </td>';
    $output.= '<td class="text-right">';
    $mail_datetime=$overview[0]->date;
    $cur_date=date('d-M-Y');
    $mail_date=date('d-M-Y', strtotime($mail_datetime));
    $mail_time=date('h:i A', strtotime($mail_datetime));
    if($cur_date==$mail_date)
    {
    $output.=$mail_time;
    }
    else
    {
    $output.=$mail_date;
    }
    $output.= '</td>
    </tr>';
    }

    echo $output;
    } 

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

 </tbody>
</table>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM