电子邮件:
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
可以是asd asd asd dasdasd asd asd
的任何东西From: Ticketing System [ts@yahoo.com]
Sent: Thursday, July 19, 2013 11:21 PM
To: uSER001, uSER002
Subject: Ticketing System
来自票务系统的内容
输出应为: 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
可以是asd asd asd dasdasd asd asd
的任何东西 -
这可以使用preg_match($pattern,$data, $matches, PREG_OFFSET_CAPTURE)
和substr
吗?
答案 0 :(得分:0)
您不能只使用preg_match来可靠地解析邮件。最好使用PHP Mime Mail Parser来执行此任务。使用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');