Skip to contentSkip to navigationSkip to topbar
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):

Hostname: email.sendgrid.biz
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:

1
<?php
2
$to = $_POST["to"];
3
$from = $_POST["from"];
4
$body = $_POST["text"];
5
$subject = $_POST["subject"];
6
$num_attachments = $_POST["attachments"];
7
8
if($num_attachments){
9
for($i = 1; $i <= $num_attachments; $i++) {
10
$attachment = $_FILES['attachment' . $i];
11
// $attachment will have all the parameters expected in a the PHP $_FILES object
12
// http://www.php.net/manual/en/features.file-upload.post-method.php#example-369
13
}
14
}
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:

1
<?php
2
$data = file_get_contents("php://input");
3
$events = json_decode($data, true);
4
5
foreach ($events as $event) {
6
// Here, you now have each event and can process them how you like
7
process_event($event);
8
}
9

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.