尝试在Azure中的VM ubuntu中使用SendGrid发送电子邮件时出错
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(), "
";
}
Since the first VM you referrence is two years old, it's possible you are using the standard port 25 to talk to SendGrid. Starting on November 15th, 2017, sending outbound email directly to external domains (such as outlook.com, gmail.com) from a Virtual machine (VM) will be made available only to certain subscription types. Outbound SMTP connections using TCP port 25 (primarily used for unauthenticated e-mail delivery) will be blocked for most new subscriptions (more details below).
More details here on options: