Codice PHP:
<?php
//require 'vendor/autoload.php'; // If you're using Composer (recommended)
// Comment out the above line if not using Composer
require("./sendgrid-php/sendgrid-php.php"); # <--- controllare che sia corretto il path con la cartella caricata
// 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("test@example.com", "Example User"); # <--- indirizzo mittente
$email->setSubject("Sending with SendGrid is Fun"); # <--- oggetto email
$email->addTo("alemoppospam@altervista.org", "Example User"); # <--- indirizzo destinatario
$email->addContent("text/plain", "and easy to do anywhere, even with PHP"); # <--- testo della email
$email->addContent(
"text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
); # <--- eventuale testo HTML della mail
$sendgrid = new \SendGrid('SG.h44LKtmiSpyxbohQP4g.rP8sp_AMtesto8hOMJBkVCapikeyvR9o1XGZyJB8DWmw'); # <--- 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";
}