Send Grid Event Web hook using php to update the record in data base of mail status
I would like to know if an event Webhook works for the free sendGrid account. I am sending my emails using API keys via sendgrid- php curl and I'm not receiving any webhook callbacks. I did set up the url in email settings and did a test nothing received at end point . When I send mail via the application, I get no webhook callbacks although I do receive the emails and the statistics in the sendgrid site.
Steps to Reproduce
1.Create an API key with all permissions in the Free account 2.In email settings, setup the event webhook 3.Send mails using the sendgrid php api using the api key 4.Check if a webhook event has been received.
Here the code for sending mail using sendgrid .
filename: mail_process.php
/* sendgrid curl method ----*/ $urls = 'https://api.sendgrid.com/'; $params = array( 'api_user' => '............', // My send grid username 'api_key' => '.............', // My send grid password 'to' => $row['email'], 'from' => '.....something', 'fromname' => ".....", 'subject' => "Sendgrid Event hook", 'html' => "thank you",
'from' => '[email protected]',
);
$request = $urls.'api/mail.send.json';
$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
Now I want to track the mail status..using sendgrid Webhook. I have search google stackover flow but I could not understand as I am new to this API thing.
What I have done is set up the Event notication active and end point path is
filename: test.php
// Get the raw POSTed data $data = file_get_contents("php://input");
// Decode said data $records = json_decode($data, true);
print_r($records); // Loop through the records foreach ($records as $record) { // Store the event // Assume store_event does your data processing and inserting //store_event($record);
// You should be able to access any parameter of the event as so
// $record["email"];
// e.g.
echo $record["email"];
echo " had an email ";
echo $record["event"];
}
Hello @Aadencoder,
I'm not sure, I will find out for you.
Hi @Aadencoder,
It is included. So I have added this issue to our backlog for deeper inspection. Thanks!
thanks, waiting for the inspection result..
Hi @Aadencoder ,
Curious to know, are you able to resolve your issue or not ?
@visabhishek Please open a new issue with details about what you're experiencing.