Working with Mandrill Webhook Data

I am trying to process Mandrill webhook data when I get a rebound. I want Mandrill to inform my application that this is a letter, and save the various data in the MySql database.

I work with PHP here, according to Mandrill, they send a URL that I give them a $ _POST request with JSON data.

Normally I would like json_decode () this request, but when I do this, it seems empty. For me, JSON looks distorted, but maybe I need to do something with it first?

This is what I get in my script:

[mandrill_events] => 
[{\"event\":\"hard_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook@mandrillapp.com\",\"sender\":\"example.sender@mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"bad_mailbox\",\"bgtools_code\":10,\"diag\":\"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\ email address for typos or unnecessary spaces.\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"ts\":1390483382},{\"event\":\"soft_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook@mandrillapp.com\",\"sender\":\"example.sender@mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"soft-bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"mailbox_full\",\"bgtools_code\":22,\"diag\":\"smtp;552 5.2.2 Over Quota\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"ts\":1390483382}]
+4
source share
1 answer

You have the option installed magic_quoteson your server.

, json_decode:

$response = json_decode(stripslashes($_RESPONSE['mandrill_events']), true);

stripslashes: http://php.net/manual/en/function.stripslashes.php

+3

Source: https://habr.com/ru/post/1523346/


All Articles