2017-04-03 98 views
0

当我通过SendGrid发送电子邮件并通过事件通知保存时将它们拉入我的数据库时,我试图拉取自定义参数。从SendGrid事件Webhook抓取自定义参数PHP

我有事件通知设置,以便在SendGrid处理完电子邮件之后,将它保存到我的数据库中,但我无法弄清楚如何拉取我发送的自定义参数。

我送的说法是这样的:

$mail->addCustomArg("campaign", "welcome69"); 

然后我遇到了试图接受它的问题(后SendGrid帖吧)

$data = file_get_contents("php://input"); 
$events = json_decode($data, true); 

foreach ($events as $event) { 
$sg_event_id = $event['sg_event_id']; 
$unique_args = $event['unique_args']; 
} 

在底部一小段代码片段中,变量$ unique_args起作用,第二个不起作用。任何帮助是极大的赞赏。

回答

1

什么Sendgrid POSTs to your hook is a JSON Object

foreach($unique_args as $field => $value) { 
} 
:您可以直接通过写类似

$unique_args = $events['unique_args']; // this is an associative array. 

您可以使用foreach循环这样演练关联数组检索unique_args