簡體   English   中英

如何在imap中使用UID回復特定的電子郵件在php中獲取電子郵件

[英]How to reply to specific email using UID in imap fetched emails in php

我已經使用SMTP gmail設置發送了電子郵件,該設置工作正常,並且我使用php的IMAP功能提取了電子郵件,並且還返回了電子郵件列表。 現在,我有了帶有其uid的電子郵件列表。 我想將回復發送至收到的電子郵件。 以下是我的cakephp IMAP代碼:

public function listMessages($params=array()) {

    $page = (isset($params['page'])) ? $params['page'] : 1;
    $per_page = (isset($params['per_page'])) ? $params['per_page'] : 10; 
    $sort = (isset($params['sort'])) ? $params['sort'] : null;
    $sorted = null;
    $limit = ($per_page * $page);
    $start = ($limit - $per_page) + 1;
    $start = ($start < 1) ? 1 : $start;
    $limit = (($limit - $start) != ($per_page-1)) ? ($start + ($per_page-1)) : $limit;
    $info = imap_check($this->imapStream);
    $limit = ($info->Nmsgs < $limit) ? $info->Nmsgs : $limit;

    if(true === is_array($sort)) {
        $sorting = array(
                    'direction' => array(   'asc' => 0,
                                            'desc' => 1),

                    'by'        => array(   'date' => SORTDATE,
                                            'arrival' => SORTARRIVAL,
                                            'from' => SORTFROM,
                                            'subject' => SORTSUBJECT,
                                            'size' => SORTSIZE));
        $by = (true === is_int($by = $sorting['by'][$sort[0]]))
                        ? $by
                        : $sorting['by']['date'];
        $direction = (true === is_int($direction = $sorting['direction'][$sort[1]]))
                        ? $direction
                        : $sorting['direction']['desc'];

        $sorted = imap_sort($this->imapStream, $by, $direction);

        $msgs = array_chunk($sorted, $per_page);
        $msgs = $msgs[$page-1];
    }
    else
        $msgs = range($start, $limit); //just to keep it consistent

    $result = imap_fetch_overview($this->imapStream, implode($msgs, ','), 0);
    if(false === is_array($result)) return false;

    //sorting!
    if(true === is_array($sorted)) {
        $tmp_result = array();
        foreach($result as $r)
            $tmp_result[$r->msgno] = $r;

        $result = array();
        foreach($msgs as $msgno) {
            $result[] = $tmp_result[$msgno];
        }
    }

    $return = array('res' => $result,
                    'start' => $start,
                    'limit' => $limit,
                    'sorting' => array('by' => $sort[0], 'direction' => $sort[1]),
                    'total' => imap_num_msg($this->imapStream));
    $return['pages'] = ceil($return['total'] / $per_page);
    return $return;
}

我已經使此功能起作用。 只需在發送電子郵件之前在主題前面添加“ Re:”即可。 Gmail會自動將其視為回復並繼續在同一主題上,而不是將其顯示為新的單獨電子郵件。

暫無
暫無

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

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