Skip to content

Instantly share code, notes, and snippets.

@TakesTheBiscuit
Created February 16, 2018 13:53
Show Gist options
  • Save TakesTheBiscuit/422ae14340ec5f9705ccb12370d4d8cd to your computer and use it in GitHub Desktop.
Save TakesTheBiscuit/422ae14340ec5f9705ccb12370d4d8cd to your computer and use it in GitHub Desktop.
Sendgrid Example
<?php
// If you are using Composer (recommended)
require 'vendor/autoload.php';
// If you are not using Composer
// require("path/to/sendgrid-php/sendgrid-php.php");
$from = new \SendGrid\Email("Example User", "test@example.com");
$subject = "Sending with SendGrid is Fun";
$to = new \SendGrid\Email("Example User", "takesthebiscuit@somewherenevereverever.co.uk");
$content = new \SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP");
$mail = new \SendGrid\Mail($from, $subject, $to, $content);
//$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid("API_KEY_GOES_HERE");
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
print_r($response->headers());
echo $response->body();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment