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:
_10Hostname: email.sendgrid.biz
_10URL: 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_15if($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_10foreach ($events as $event) {_10 // Here, you now have each event and can process them how you like_10 process_event($event);_10}