2016-07-03 5 views
-1

失敗した配信メールを解析してから再度送信するためにデータベースにログインしていますが、preg_matchセクションで失敗しています。パターンが正しいと確信していますが、何度もregex101.comでチェックされていますが、関数の結果は常にfalseです。 $メッセージの正規表現を使用して配信エラーを取得する

$inbox = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $username, $pass) or die('Cannot connect to gmail: ' . imap_last_error()); 

$emails = imap_search($inbox, 'SINCE ' . $since); 
$invalidEmails = array(); 
if ($emails) { 
    rsort($emails); 
    foreach ($emails as $email) { 
     $message = imap_fetchbody($inbox, $email, 1); 
     if(preg_match("/^Delivery to the following recipient failed permanently:\n\n\s+(.+)/im", $message, $matches)) { 
      Debugger::log("mail found"); 
     } 

     array_push($invalidEmails, $matches); 

     if(preg_match("/^Delivery to the following recipient has been delayed:\n\n\s+(.+)/im", $message, $matches)) { 
      Debugger::log("mail found"); 
     } 

     array_push($invalidEmails, $matches); 
    } 
} 

imap_close($inbox); 

内容:

Delivery to the following recipient failed permanently: 

    [email protected] 

Technical details of permanent failure:=20 
Google tried to deliver your message, but it was rejected by the server for= 

私は誰かが問題になる可能性があるかを知ることができ、この数時間で立ち往生していますか?

+0

によって

preg_match("/^Delivery to the following recipient failed permanently:\n\n\s+(.+)/im", $message, $matches) 

を交換しては永久に失敗しました:\ S +(+)/イム "? – OOPer

+0

ありがとう、愚かな間違い-_- – Syntey

+0

私があなたの問題を解決するのに役立つことができれば、それは私の喜びです。一般に、行区切り文字を '\ n'と一致させると、いくつかの問題が発生する可能性があります。 – OOPer

答えて

0

次の受信者に `"/^配達にあなたの最初のパターンを変更した場合、あなたはどのような結果を得るのですか

preg_match("/^Delivery to the following recipient failed permanently:\s+(.+)/im", $message, $matches) 
関連する問題