sonam Sharma sonam Sharma - 1 year ago 81
PHP Question

"Unsupported SSL protocol version" when trying to call SendGrid API

hello all please take a look at the below codes and help me to figure out the issue ..

$subject09='hello madam223';
$messageto90='this is a test';
$myName_emailis='Sonam verma';
$json_string = array( 'to' =>$emaillist_act,'category' => 'activity');

$url = '';
$user = 'username';
$pass = 'password';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'x-smtpapi' => json_encode($json_string),
'to' => "$tos",
'subject' => "$subject09",
'html' => "$messageto90",
'fromname' => $myName_emailis,
'from' => " <>"
$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);

This code works on other server
but it dosent do anything on my server
it dosent prints aything it is supposed to print the response success or fail etc..

This code works great on both the server.

//Your authentication key
$authKey = "somethingapikey";

//Multiple mobiles numbers separated by comma
$mobileNumber = "$mobileno";

//Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "something";

//Your message to send, Add URL encoding here.

if(strlen($textsms) > 300){
$message = urlencode(substr($textsms,0,300));
$message=$message.'...'. '';
$message = urlencode($textsms);

//Define route
$route = "domain";
//Prepare you post parameters
$postData = array(
'authkey' => $authKey,
'mobiles' => $mobileNumber,
'message' => $message,
'sender' => $senderId,
'route' => $route
// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,

//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

//get response
$output = curl_exec($ch);
//Print error if any
// echo 'error:' . curl_error($ch);
//echo $output;

Please help me narrow down the issue as this is very important for me please ...
My server admin says they cant help .

i also narrowed the issue we have curl version 7.38.0 and other server has 7.19.7

All the error reportings are on but still i am not getting anything no errors no success no mail.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

After adding the

$error = curl_error($session);
echo $error;

i get

Unsupported SSL protocol version

Answer Source

Try to use a different SSL protocol version.

Change the line:

@curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);

Try these possible constants to see which one works:


Also: Remove the @ from the beginning of the line. The @suppresses errors. You do want to get errors when any occur.

If neither works, maybe support for the required ssl protocol version is not installed on the server. You would then need to update the CURL used or the OPENSSL used on the server.