在php中从电子邮件中获取新邮件而无需回复
我正在开发电子邮件应用程序。我编写的代码可以从服务器获取电子邮件(我正在gmail服务器上测试) 电子邮件,我尝试获取电子邮件文本正文,但在回复邮件时也会附加原始邮件。因此,我希望获取新邮件时不加任何内容 附加的回复消息。将通知任何帮助。我的代码如下:在php中从电子邮件中获取新邮件而无需回复,php,email,gmail,Php,Email,Gmail,我正在开发电子邮件应用程序。我编写的代码可以从服务器获取电子邮件(我正在gmail服务器上测试) 电子邮件,我尝试获取电子邮件文本正文,但在回复邮件时也会附加原始邮件。因此,我希望获取新邮件时不加任何内容 附加的回复消息。将通知任何帮助。我的代码如下: /* connect to gmail */ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = 'mahmoodkk@gmail.com'; $password = 'ma
/* 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); .
/*连接到gmail*/
$hostname='{imap.gmail.com:993/imap/ssl}收件箱';
$username='1mahmoodkk@gmail.com';
$password='mahmood';
$inbox=imap_open($hostname,$username,$password)或die('cannotconnecttogmail:'。imap_last_error());
$emails=imap_搜索($inbox,'ALL');
/*如果电子邮件被返回,请循环浏览每个*/
如果($电子邮件){
$output='';
rsort(电子邮件);
foreach($email作为$email\u编号){
/*获取此电子邮件的特定信息*/
$overview=imap\U fetch\U overview($inbox,$email\u number,0);
$message=imap\u fetchbody($inbox,$email\u number,2);
/*输出电子邮件标题信息*/
$output.='';
$output.=''.$overview[0]->subject';
$output.=''.$overview[0]->from';
$output.='on'.$overview[0]->date'.';
$output.='';
/*输出电子邮件正文*/
$output.=''.$message';
echo$message;//这里我想将附加消息和新消息分开。
}
}
imap_close($inbox)。
我得到了这个输出:
如果您看到上图,行上方是新消息或原始消息,而行下方是附加消息(原始消息附加到新消息)。我只想获取新消息而不获取附加消息。请提前感谢@Mahmood Rehman您实现了本文: 我希望下一行能帮助你 您认为使用PHP DOM()好吗
还有更具体的DOMDocument::loadHTML和DomeElement::getElementsByTagName。谢谢。是的,我实现了这段代码。但是我如何在消息中使用DomeElement::getElementsByTagNam呢?示例:domeElement::getElementsByTagNam('div');或domeElement::getElementsByTagNam('table');这类似于JavaScript/jQuery或:DOMDocument::getElementByIdi通过实现domphp页面中的代码实现了这一点。感谢您的帮助。