1

这个 PHP 函数工作得很好:

if (preg_match ("/<(\S+@\S+\w)>.*\n?.*55[0-9]/i",$body,$match)) {
echo "found!";
}

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

xxx@hotmail.com
SMTP error from remote mail server after RCPT TO:<xxx@hotmail.com>:
host mx3.hotmail.com [65.54.188.72]: 550 Requested action not taken:
mailbox unavailable

但是如果我在这种情况下使用相同的 php 函数:

A message that you sent could not be delivered to one or more of its 
recipients. This is a permanent error. The following address(es) failed:

xxx@yahoo.com
SMTP error from remote mail server after end of data:
host d.mx.mail.yahoo.com [209.191.88.254]: 554 delivery error:
dd This user doesn't have a yahoo.com account (xxxd@yahoo.com) [0] -  mta1010.mail.mud.yahoo.com

preg_match函数不给出任何结果。我究竟做错了什么?

4

2 回答 2

4

您基本上是在寻找包含在<和中的电子邮件地址>

您的第一个输入有它,但第二个输入没有:它没有电子邮件 ID,< >因此您没有得到匹配。

编辑:(在您发表评论后):

查看您提供的 2 个示例,电子邮件 ID 出现在字符串failed:和以 . 开头的错误代码之间55。您可以为此使用 preg_match :

if(preg_match('/failed:.*?(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b).*55[\d]/is',$str,$m)) {
       echo "Bounced email ".$m[1]."\n";
}

ideone链接

于 2010-12-01T16:32:54.173 回答
0

默认情况下,preg_match 不支持解析多行字符串(包含 \n 的字符串),因此您必须传入额外的参数来匹配整个字符串,即 m(多行)。

尝试

if (preg_match ("/<(\S+@\S+\w)>.*\n?.*55[0-9]/im",$body,$match)) {
echo "found!";
}
于 2010-12-01T16:24:27.990 回答