从标题中提取电子邮件

Can't seem to get my code to work. Warning: preg_match_all() expects parameter 2 to be string, array given in /script.php on line 23. I am looking to retrieve a list of emails addresses:

<?php
$mbox = imap_open("{******.com:143/notls}", "******@******.com", "******");

echo "<h1>Email Addresses</h1>
";
$headers = imap_headers($mbox);

if ($headers == false) {
echo "Call failed<br />
";
} else {
foreach ($headers as $val) {
preg_match_all('/([^: ]+): (.+?(?:
\s(?:.+?))*)
/m', $headers, $matches);
echo $maches[2] . "<br />
";
}
}

imap_close($mbox);
?>
preg_match_all('/([^: ]+): (.+?(?:
\s(?:.+?))*)
/m', $headers, $matches);

should be

preg_match_all('/([^: ]+): (.+?(?:
\s(?:.+?))*)
/m', $val, $matches);

You were looping through the array, but feeding the entire array into the preg_match_all function each loop.

Also, you have a typo:

echo $maches[2] . "<br />
";

should be

echo $matches[2] . "<br />
";