Reputation: 4692
I am trying to post SendGrid events back to my server. But I am not able to capture the data. When I try from the testing functionality, it is showing the response code as 200 and the posted data. But I am not able to capture it in my server side. I am using the following code
<?php
$postText = trim(file_get_contents('php://input'));
print_r($postText);
$fh = fopen('/tmp/dump.log','a+');
fwrite($fh,print_r($postText),'true');
fclose($fh);
?>
Nothing is written to the file. I tried to write something to same file for testing and it is working. So I think the file has all the permissions.
Upvotes: 0
Views: 293
Reputation: 2874
This is because you print the data by not passing second argument to the print_r
function!
This line: fwrite($fh,print_r($postText),'true');
should look like this instead: fwrite($fh,print_r($postText, true));
Upvotes: 1
Reputation: 4326
I know this is already working, but wanted to share some sample code I use myself. (disclosure: I'm a SendGrid employee)
Very similar to your own code, but the RAW_POST_DATA global makes it pretty easy to fetch all POST data in one shot.
<?php
$fh = fopen("/tmp/sg_event.log", 'a+');
if ($fh) {
fwrite($fh, print_r($HTTP_RAW_POST_DATA, true));
fclose($fh);
}
?> ok
Upvotes: 2