当正文如下所示时,我正在尝试从转发的电子邮件中获取电子邮件并抄送:
$body = '-------
Begin forwarded message:
From: Sarah Johnson <blabla@gmail.com>
Subject: email subject
Date: February 22, 2013 3:48:12 AM
To: Email Recipient <thatwouldbe@yayyy.com>
Cc: Ralph Johnson <johnson@gmail.com>
Hi,
hello, thank you and goodbye!
blabla@gmail.com'
现在,当我执行以下操作时:
$body = strtolower($body);
$pattern = '#from: \D*\S([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})\S#';
if (preg_match($pattern, $body, $arr_matches)) {
echo htmlentities($arr_matches[0]);
die();
}
我正确地得到:
from: sarah johnson <blabla@gmail.com>
现在,为什么cc不起作用?我做了一些非常相似的事情,只是从更改为 cc:
$body = strtolower($body);
$pattern = '#cc: \D*\S([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})\S#';
if (preg_match($pattern, $body, $arr_matches)) {
echo htmlentities($arr_matches[0]);
die();
}
我得到:
cc: ralph johnson <johnson@gmail.com> hi, hello, thank you and goodbye! blabla@gmail.com
如果我从原始正文页脚中删除电子邮件(删除 blabla@gmail.com),那么我正确地得到:
cc: ralph johnson <johnson@gmail.com>
看起来该电子邮件正在影响正则表达式。但是如何,为什么它不影响它?我怎样才能解决这个问题?