dream543211 2014-11-18 02:50
浏览 60
已采纳

从标题中提取电子邮件

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);
?>
  • 写回答

1条回答 默认 最新

  • dtsps2098 2014-11-18 03:05
    关注
    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 />
    ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?