0

电子邮件:

你好世界 123 123


From: uSER001 [user001@yahoo.com]
Sent: Thursday, July 19, 2013 11:21 PM
To: ts@yahoo.com
Subject: Re: Ticketing System

可以是任何东西 sd asd asd asd asd asda dasdasd asda asd


From: Ticketing System [ts@yahoo.com]
Sent: Thursday, July 19, 2013 11:21 PM
To: uSER001, uSER002
Subject: Ticketing System

票务系统的内容


票务系统http://www.yahoo.com

输出应该是: Hello World 123 123


From: uSER001 [user001@yahoo.com]
Sent: Thursday, July 19, 2013 11:21 PM
To: ts@yahoo.com
Subject: Re: Ticketing System

可以是任何东西 sd asd asd asd asd asda dasdasd asda asd

- 这可以使用preg_match($pattern,$data, $matches, PREG_OFFSET_CAPTURE)andsubstr吗?

4

1 回答 1

0

您不能只使用 preg_match 来可靠地解析邮件消息。最好使用PHP Mime 邮件解析器来完成此任务。使用 Mime Mail Parser 代码将非常简单:

require_once('MimeMailParser.class.php');

$path = 'path/to/mail.txt';

$Parser = new MimeMailParser();
$Parser->setPath($path);

$to       = $Parser->getHeader('to');
$from     = $Parser->getHeader('from');
$subject  = $Parser->getHeader('subject');
$textBody = $Parser->getMessageBody('text');
$htmlBody = $Parser->getMessageBody('html');
于 2013-07-19T09:52:54.053 回答