I am a newbie to php, azure, and sendgrid.
here is some code I found that I am trying to use for the html form.
As you hadn’t defined $curl
before setting parameters using curl_setopt
, and here is a code sample on SendGrid code examples page, please try it:
$user,
'api_key' => $pass,
'to' => 'example3@sendgrid.com',
'subject' => 'testing from curl',
'html' => 'testing body',
'text' => 'testing body',
'from' => 'example@sendgrid.com',
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
print_r($response);
?>
If you get error message as not defined constant CURL_SSLVERSION_TLSv1_2, we can directly set integer variable to CURLOPT_SSLVERSION
.
We can find details in http://php.net/manual/en/function.curl-setopt.php:
One of CURL_SSLVERSION_DEFAULT (0), CURL_SSLVERSION_TLSv1 (1), CURL_SSLVERSION_SSLv2 (2), CURL_SSLVERSION_SSLv3 (3), CURL_SSLVERSION_TLSv1_0 (4), CURL_SSLVERSION_TLSv1_1 (5) or CURL_SSLVERSION_TLSv1_2 (6).
set as: curl_setopt($session, CURLOPT_SSLVERSION, 6);
And I have to set an additional option :
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
so that I can succeed to set my request to SendGrid Server.