I need to parse mail received from postfix in php structure like as headers array, plain/text body string and html body string.
I'm testing the examples from https://www.thecodingmachine.com/triggering-a-php-script-when-your-postfix-server-receives-a-mail/ for receive all letters to my php-script. But examples from this page is abandoned or not work like as I want.
I would like to have something like:
$message_from_postfix = "Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1])
by DavidUbuntu (Postfix) with ESMTPS id 740AD380597
for <david@localhost>; Thu, 5 Jan 2012 10:04:48 +0100 (CET)
Message-ID: <1325754288.4989.6.camel@DavidUbuntu>
Subject: my title
From: David Negrier <david@localhost>
To: david@localhost
Date: Thu, 05 Jan 2012 10:04:48 +0100
Content-Type: text/plain
X-Mailer: Evolution 3.2.0-
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0
my mail content";
$data = ParseMessage($message_from_postfix);
echo $data->headers()['from']; // david@localhost
echo $data->headers()['to']; // david@localhost
echo $data->headers()['date']; // 1325757888
echo $data->text_message(); // my mail content
echo $data->html_message(); // (empty)
I found: https://github.com/php-mime-mail-parser/php-mime-mail-parser
This is probably the best solution for me.