Skip to content

Instantly share code, notes, and snippets.

@pridemusvaire
Forked from sendgrid-gists/v3-hello-email.php
Created July 15, 2016 11:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pridemusvaire/5dc5eb1b9b2d0ec737b972ed86b46130 to your computer and use it in GitHub Desktop.
Save pridemusvaire/5dc5eb1b9b2d0ec737b972ed86b46130 to your computer and use it in GitHub Desktop.
v3 "Hello World" for email, using SendGrid with PHP.
// using SendGrid's PHP Library
// https://github.com/sendgrid/sendgrid-php
<?php
// If you are using Composer
require 'vendor/autoload.php';
// If you are not using Composer (recommended)
// 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", "test@example.com");
$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($apiKey);
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
echo $response->headers();
echo $response->body();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment