1008 echo "sendgrid.env" >> .gitignore
1009 source ./sendgrid.env
1013 composer sendgrid/sendgrid
1014 sudo curl -sS https://getcomposer.org/installer | php
1015 mv composer.phar /usr/local/bin/composer
1016 composer -V
1023 composer require sendgrid/sendgrid
---------------------------------------------------------------------
PHP CODE
<?php
require 'vendor/autoload.php'; // If you're using Composer (recommended)
// Comment out the above line if not using Composer
// require("<PATH TO>/sendgrid-php.php");
// If not using Composer, uncomment the above line and
// download sendgrid-php.zip from the latest release here,
// replacing <PATH TO> with the path to the sendgrid-php.php file,
// which is included in the download:
// https://github.com/sendgrid/sendgrid-php/releases
$email = new \SendGrid\Mail\Mail();
$email->setFrom("admin@asterisk-voip.com", "Ambiorix Rodriguez");
$email->setSubject("Sending with SendGrid is Fun");
$email->addTo("ambiorixg12@gmail.com", "Example User");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
"text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
$response = $sendgrid->send($email);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}
?>