1. Install: composer require sendgrid/sendgrid.
2. Build and send:
require 'vendor/autoload.php';
use \SendGrid\Mail\Mail;
$email = new Mail();
$email->setFrom('[YOUR_VERIFIED_SENDER]', 'Your Name'); // verified sender
$email->setSubject('subject here');
$email->addTo('[RECIPIENT_EMAIL]', 'Their Name');
$email->addContent('text/plain', 'plain body');
$email->addContent('text/html', '[strong]html body[/strong]');
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
$response = $sendgrid->send($email);
printf("Response status: %d\n", $response->statusCode()); // 202 means accepted
} catch (Exception $e) {
echo 'Caught exception: ' . $e->getMessage() . "\n";
}
3. Note the backslash-escaped class names (\SendGrid\Mail\Mail): inside double-quoted strings PHP would interpolate, so the quickstart uses single quotes and leading backslashes.
4. The from address must be a verified sender or the send fails.
5. Read the key from the environment with getenv. Do not commit it, and do not echo it in error output.