Mailgun Webhook跟踪事件:如何将输出传递给数据库

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

duancai7002
duancai7002 当然是Alister-一个看起来像阵列的字符串...非常感谢。
3 年多之前 回复
dongyinglan8707
dongyinglan8707 你在一个字符串上做一个ForEach。你想要循环遍历数据-$_POST['message-headers'],至少-解码你在$postdata中获得的JSON之后。
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐