コマンドmailq
を実行して、その出力を多次元配列の値に変換するのに問題があります。
$results = array();
exec('/usr/bin/mailq', $mailQresult);
foreach ($mailQresult as $key => $mailqLine) {
$res = preg_match('/^([A-Z0-9]{1,20})\s+([1-9][0-9]*)\s+((Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s+[A-Za-z]{3}\s+[0-9]{2}\s+[0-9]{2}\:[0-9]{2}\:[0-9]{2})\s*$/', $mailqLine, $matches);
if ($res) {
// Insert message ID and other data into the object.
// It will be competed afterwards.
$mailqArray = array(
'id' => $matches[1],
'size' => intval($matches[2]),
'date' => strftime($matches[3]),
'sender' => $matches[5],
'failed' => false,
'recipients' => $matches[4]
);
}
}
の出力にmailq
は空白が含まれ、戻り値は次のようになります。
ID SIZE DAYNAME MONTH DAY HOUR:MINUTES:SECONDS sender@address.com [new line here]
(Host or domain name not found. Name service error for name=address.com type=MX: Host not found, try again) [new line here]
recipient@address.com
そのため、エラー メッセージと受信者は異なるキーになります。
shell_exec を使用して mailq の出力を 1 つの文字列として取得できることはわかっていますが、多次元配列を作成する正規表現の書き方がわかりません。
私はこれに間違って近づいているかもしれません。どんなアドバイスでも大歓迎です!