这个PHP函数工作正常:
if (preg_match ("/<(\S+@\S+\w)>.*\n?.*55[0-9]/i",$body,$match)) {
echo "found!";
}
in
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
函数不会给出任何结果。我做错了什么?
答案 0 :(得分: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";
}
答案 1 :(得分:0)
默认情况下,preg_match不支持解析多行字符串(包含\ n的字符串),因此你必须传入额外的参数来匹配整个字符串,即m(多行)。
试
if (preg_match ("/<(\S+@\S+\w)>.*\n?.*55[0-9]/im",$body,$match)) {
echo "found!";
}