0

メールをチェックしてデータベースに入れるスクリプトがあります。これは、新しい電子メールが作成されて送信されるときに正常に機能します。ただし、電子メールに返信すると、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_new の代わりに $message を出力すると、テキストの削除を開始する前にすべてが表示されます。

4

1 に答える 1

0

その行「返信中...」がメッセージにまったく存在しない場合、strposは boolean を返し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);
于 2012-08-31T01:03:00.967 に答える