获取新消息,而无需在php中发送电子邮件 [英] Fetch New message without reply from email in php

查看:171
本文介绍了获取新消息,而无需在php中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事电子邮件应用程序。我编写的代码可以从服务器(当前我在gmail服务器上测试)获取电子邮件。当我发现特定的
电子邮件时,我尝试获取电子邮件文本正文,但是回复的消息orignal消息也被追加。所以我想得到新的消息与
被回复的消息被追加。任何帮助将被appricaited.My代码如下:

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

$ inbox = imap_open($ hostname,$ username,$ password)或死(无法连接到Gmail:imap_last_error());


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

/ *如果返回电子邮件,请循环遍历每个... * /
if($ emails){

$ output ='';

rsort($ emails);

foreach($ emails as $ email_number){

/ *获取特定于此电子邮件的信息* /
$ overview = imap_fetch_overview($ inbox,$ email_number, 0);
$ message = imap_fetchbody($ inbox,$ email_number,2);

/ *输出电子邮件标题信息* /
$ output。='< div class =toggler'($ overview [0] - > '未读') '>'。
$ 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。='< div class =body>'。$ message。'< / div>';
echo $ message; //这里我想分开附加的和新的消息。
}


}

imap_close($ inbox); 。

我得到这个输出:

如果您看到上面的图像,上面的是新的或原始的消息,而下面的行是附加的消息(原始消息附加到新的信息 )。我只想获取新消息而不附加消息。提前提交

解决方案

@Mahmood Rehman你实现这篇文章: a href =http://davidwalsh.name/gmail-php-imap =nofollow> http://davidwalsh.name/gmail-php-imap ?



我希望下一行可以帮助你。



你认为是好主意吗?PHP DOM( http://php.net/manual/en/book.dom.php



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


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

解决方案

@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.

这篇关于获取新消息,而无需在php中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆