curl函数或发送网格电子邮件api没有在我的服务器上运行


curl function or send grid email api not running on my server

我以前用这个代码发送电子邮件:

    <?php
   $tos='sonam2@gmail.com';
  $subject09='hello madam223';
  $messageto90='this is a test';
  $myName_emailis='Sonam ';
 $emaillist_act=array('Sonam@gmail.com','sakshiprakas@gmail.com');
 $json_string = array( 'to' =>$emaillist_act,'category' => 'activity');
$url = 'https://api.sendgrid.com/';
 $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'      => "domain.com <contact@domain.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_r($response);
?>

但现在相同的代码什么都做不了。它既不打印响应,也不发送电子邮件。

我想可能是我的服务器上没有安装curl,所以我通过curl函数和进行了检查

 function _is_curl_installed() {
if  (in_array  ('curl', get_loaded_extensions())) {
    return true;
}
else {
    return false;
}
}

这让我明白了。。

可能的原因是什么?请帮帮我。它仍然在其他服务器上打印成功消息,而不是在我的服务器上。可能是什么问题??

尝试在api url中发送api userid、api密钥。旋度不需要单独定义。我使用以下代码来获取json数据,它是有效的。

$json_url = "https://httpapi.com/api/products/reseller-price.json?auth-userid";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL, $json_url);
$str = curl_exec($ch);
$ar = json_decode($str,true);
  echo $ar['domcno'][0]['pricing']['addnewdomain'][1];