Fetch New message without reply from email in php

你。 提交于 2019-12-11 16:00:13

问题


I am working on email application.I write code that can fetch emails from server ( currentyl i am testing on gmail server).when i retrive specific emails ,i try to get email text body ,but with the replied message orignal message is also appended .So i want to get the new message with out the replied message that are appended.Any help will be appricaited.My code is below :

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

I got this output :

If you see above image , above the line is the new or original message while below line is the appended message ( original message appended to new message ). I want to fetch only the new message without the appended message.thanks in advance

回答1:


@Mahmood Rehman you implement this Article : http://davidwalsh.name/gmail-php-imap ???

I hope next lines to help you.

Do you think is good idea to use : PHP DOM (http://php.net/manual/en/book.dom.php)

And more specific DOMDocument::loadHTML AND DOMElement::getElementsByTagName.



来源:https://stackoverflow.com/questions/18584244/fetch-new-message-without-reply-from-email-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!