如何使用PHP

时间:2015-05-24 01:47:05

标签: php email

我有一段纯文本电子邮件的文本,出于各种原因,我试图从链中较低的电子邮件(电子邮件已转发)中的标题中读取信息 - 所以字符串如下所示:

Jonathan Nathanson

Technology Consultant

Excell One Number: 0203 176 1025



From: Matthew Smith [mailto:Matthew.Smith@playspace.co.uk]

Sent: 22 May 2015 16:28

To: 'janine@greatplaces.co.uk'

Cc: Mark McIntyre;

Subject: GG.505 Treadmore Place - GreatPlaces 



Dear Janine,



Please find attached an o....

我想阅读' From:'中的姓名和电子邮件地址等信息。行,来自' To:'的电子邮件地址行和主题行中的信息。

有没有人有任何能帮我上路的指针?

非常感谢。

1 个答案:

答案 0 :(得分:1)

以下内容对您有所帮助:

$re1 = '~(?<=From: )(.*?)(?: \[mailto:)(.*?)(?=\])~';
$re2 = "~(?<=To: ').*(?=')~";
$re3 = "~(?<=Subject:\s)(.*?)(?=\s)(?:.*\s\-\s)(.*)~";

if(preg_match($re1, $str, $matches1)) {
    $from_name = $matches1[1];
    $from_email = $matches1[2];
}
if(preg_match($re2, $str, $matches2))
    $to_email = $matches2[0];
if(preg_match($re3, $str, $matches3)) {
    $Subject_code = $matches3[1];
    $Subject_nameAfterHyphen = $matches3[2];
}