douteng5673 2017-04-03 22:01
浏览 42

从SendGrid事件Webhook PHP中获取自定义参数

I'm trying to pull custom arguments when I send email through SendGrid and pull them into my database when they are saved through Event Notification.

I have event notification setup so that after SendGrid processes email, it saves it into my DB, I just can't figure out how to pull the custom arguments I'm sending.

I send the argument like this:

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

And then am running into issues trying to receive it (after SendGrid posts it)

$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'];
}

In the bottom code snipet, the variable $unique_args works, the second one does not. Any help is greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dongzhuner6981 2017-04-03 22:10
    关注

    What Sendgrid POSTs to your hook is a JSON Object. You can retrieve unique_args directly by writing something like

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

    You can walkthrough the associative array using a foreach loop this way:

    foreach($unique_args as $field => $value) {
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改