PHP code example of xedi / sendgrid
1. Go to this page and download the library: Download xedi/sendgrid library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xedi / sendgrid example snippets
Xedi\SendGrid\Contracts\Exception as SendGridException;
use Xedi\SendGrid\SendGrid;
SendGrid::setClient(
SendGrid::getApiClient($api_key)
);
($mailable = SendGrid::prepareMail())
->setSender('[email protected]', 'Joe Blogs')
->setSubject('Checkout XEDI\'s SendGrid library!')
->addTextContent('Hey,\n\rI found this great SendGrid library!')
->addHtmlContent('<body>Hey,<br/>I found this great SendGrid library!</body>')
->addRecipient('[email protected]', 'John Smith');
try {
SendGrid::send($mailable);
} catch (SendGridException $exception) {
echo 'Caught exception: ' . (string) $exception;
}