SendGrid Azure I have a VM with Ubuntu that I created 2 year ago in azure, In which I can send email throw SendGrind with no problems.
Now I create an other VM with ubuntu, I copied the same code that I have in the other server and nothing works. I get an 500 error. If I commented the next line the error is gone but I don't know why there is a problem:
$response = $sendgrid->send($email);
I don't remember if I need to install something in the server, I hope you have some ideas.
require("../sendgrid-php/sendgrid-php.php");
//If not using Composer, uncomment the above line
$email = new \SendGrid\Mail\Mail();
$email->setFrom("xxxxx@gmail.com", "Example User");
$email->setSubject("Sending with SendGrid is Fun");
$email->addTo("xxxxxxx@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('the-key'));
try {
$response = $sendgrid->send($email);
print $response->statusCode(). "
";
print_r($response->headers());
print $response->body() . "
";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "
";
}