【问题标题】:Fetch New message without reply from email in php获取新消息而不从php中的电子邮件回复
【发布时间】:2013-09-06 05:07:32
【问题描述】:

我正在开发电子邮件应用程序。我编写可以从服务器获取电子邮件的代码(目前我正在 gmail 服务器上测试)。当我检索特定的 电子邮件,我尝试获取电子邮件正文,但回复的消息也附加了原始消息。所以我想得到新消息而不 附加的回复消息。任何帮助都将得到应用。我的代码如下:

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

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


$emails = imap_search($inbox,'ALL');

/* if emails are returned, cycle through each... */
if($emails) {

    $output = '';

    rsort($emails);

    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,2);

        /* 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]->date.'</span>';
        $output.= '</div>';

        /* output the email body */
        $output.= '<div class="body">'.$message.'</div>';
        echo $message; // here i want to seperate the appended and new message.
    }


} 

imap_close($inbox); .

我得到了这个输出: 如果您看到上图,则行上方是新消息或原始消息,而行下方是附加消息(原始消息附加到新消息)。我只想获取没有附加消息的新消息。提前谢谢

【问题讨论】:

    标签: php email gmail


    【解决方案1】:

    @Mahmood Rehman 你实现了这篇文章:http://davidwalsh.name/gmail-php-imap ???

    我希望下一行对你有所帮助。

    你认为使用 PHP DOM (http://php.net/manual/en/book.dom.php) 是个好主意

    还有更具体的 DOMDocument::loadHTML AND DOMElement::getElementsByTagName。

    【讨论】:

    • 谢谢,是的,我实现了该代码。但是我如何使用 DOMElement::getElementsByTagNam 获取消息。 ?
    • 示例:DOMElement::getElementsByTagNam('div');或 DOMElement::getElementsByTagNam('table');这就像 JavaScript/jQuery 或:DOMDocument::getElementById
    • 我是通过实现 dom php 页面中的代码来实现的。感谢您的帮助。
    猜你喜欢
    • 2012-04-15
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2017-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多