Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Event Webhook PHP Code Example



Parse Webhook

parse-webhook page anchor

In this example, we want to parse all emails at address@email.sendgrid.biz and post the parsed email to https://sendgrid.com/email.php.

Given this scenario, the following are the parameters you would set at the Parse API settings page(link takes you to an external page):


_10
Hostname: email.sendgrid.biz


_10
URL: https://sendgrid.com/email.php

To test this scenario, we sent an email to example@example.com and created the following form at https://sendgrid.com/email.php:


_15
<?php
_15
$to = $_POST["to"];
_15
$from = $_POST["from"];
_15
$body = $_POST["text"];
_15
$subject = $_POST["subject"];
_15
$num_attachments = $_POST["attachments"];
_15
_15
if($num_attachments){
_15
for($i = 1; $i <= $num_attachments; $i++) {
_15
$attachment = $_FILES['attachment' . $i];
_15
// $attachment will have all the parameters expected in a the PHP $_FILES object
_15
// http://www.php.net/manual/en/features.file-upload.post-method.php#example-369
_15
}
_15
}
_15
?>


To use the Event Webhook, you must first setup Event Notification.

In this scenario, we assume you've set the Event Notification URL to go the endpoint /parse.php on your server. Given this scenario the following code will allow you to process events:


_10
<?php
_10
$data = file_get_contents("php://input");
_10
$events = json_decode($data, true);
_10
_10
foreach ($events as $event) {
_10
// Here, you now have each event and can process them how you like
_10
process_event($event);
_10
}


Rate this page: