【问题标题】:Grab Custom Arguments from SendGrid Event Webhook PHP从 SendGrid 事件 Webhook PHP 中获取自定义参数
【发布时间】:2017-04-03 22:01:46
【问题描述】:

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

我设置了事件通知,以便在 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 有效,第二个无效。非常感谢任何帮助。

【问题讨论】:

    标签: php sendgrid sendgrid-api-v3


    【解决方案1】:

    什么Sendgrid POSTs to your hook is a JSON Object。您可以通过编写类似的内容直接检索unique_args

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

    您可以通过这种方式使用 foreach 循环遍历关联数组:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      相关资源
      最近更新 更多