sendgrid-php icon indicating copy to clipboard operation
sendgrid-php copied to clipboard

Send Grid Event Web hook using php to update the record in data base of mail status

Open Aadencoder opened this issue 9 years ago • 6 comments

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"];

}

Aadencoder avatar May 25 '17 11:05 Aadencoder

Hello @Aadencoder,

I'm not sure, I will find out for you.

thinkingserious avatar May 26 '17 17:05 thinkingserious

Hi @Aadencoder,

It is included. So I have added this issue to our backlog for deeper inspection. Thanks!

thinkingserious avatar May 26 '17 17:05 thinkingserious

thanks, waiting for the inspection result..

Aadencoder avatar May 28 '17 11:05 Aadencoder

Hi @Aadencoder,

Did you start with this guide?

thinkingserious avatar May 30 '17 21:05 thinkingserious

Hi @Aadencoder ,

Curious to know, are you able to resolve your issue or not ?

visabhishek avatar Aug 31 '20 10:08 visabhishek

@visabhishek Please open a new issue with details about what you're experiencing.

childish-sambino avatar Aug 31 '20 16:08 childish-sambino