imap_fetchbody和线下剥离


imap_fetchbody and stripping below line

我有一个检查电子邮件并将其放入数据库的脚本。当编写和发送新的电子邮件时,这种方法很好。但是,如果我回复一封电子邮件,imap_fetchbody将不起作用,并且它是空的。

我哪里错了?

/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$structure = imap_fetchstructure($inbox,$email_number);
$message = imap_fetchbody($inbox,$email_number,0);
$header = imap_headerinfo($inbox,$email_number);
//print_r($structure);
  //make sure emails are read or do nothing
if($overview[0]->seen = 'read'){  
//strip everything below line
$param="## In replies all text above this line is added to the ticket ##";
$strip_func = strpos($message, $param);
$message_new = substr($message,0,$strip_func );

  /* output the email body */
  $output.= '<div class="body">'.$message_new.'<br><br></div>';

如果我输出$message而不是$message_new,那么在我开始剥离文本之前,所有内容都会显示出来。

如果消息中根本不存在"In replies…"这一行,strpos将返回布尔值false,当强制为整数时,该值将为0。

因此,当你要求从0到位置的子字符串时,你要求的是从0到0的子字符串,而$message_new是空的。

在您尝试基于该行提取子字符串之前,请检查邮件中是否存在该行。

$param="## In replies all text above this line is added to the ticket ##";
$strip_func = strpos($message, $param);
$message_new = ($strip_func === false) ? $message : substr($message,0,$strip_func);