I am using a Mailgun Webhook to track events (delivered, opened, etc). I successfully redirected the event to a url that has a php file that looks like this:
<?php
$postdata = file_get_contents("php://input");
$postdata_encoded = json_encode($_POST['message-headers']);
When I echo the output I am getting the following:
[[\"Received\", \"by luna.mailgun.net with SMTP mgrt 8734663311733; Fri, 03 May 2013 18:26:27 +0000\"], [\"Content-Type\", [\"multipart/alternative\", {\"boundary\": \"eb663d73ae0a4d6c9153cc0aec8b7520\"}]], [\"Mime-Version\", \"1.0\"], [\"Subject\", \"Test deliver webhook\"], [\"From\", \"Bob \"], [\"To\", \"Alice \"], [\"Message-Id\", \"<20130503182626.18666.16540@mail.example.com>\"], [\"X-Mailgun-Variables\", \"{\\"my_var_1\\": \\"Mailgun Variable #1\\", \\"my-var-2\\": \\"awesome\\"}\"], [\"Date\", \"Fri, 03 May 2013 18:26:27 +0000\"], [\"Sender\", \"bob@mail.example.com\"]]
Question: How can I transform this output to a proper json format that I will be able to pass to my database? I tried something like this:
$output = array();
foreach ($postdata_encoded as $key=>$value) {
$output[$key] = $value;
}
var_dump($output);
but this returns:
Response: array(0) { }
Any idea? Many thanks