Sendgrid PHP使用未定义的常量CURL_SSLVERSION_TLSv1_2

I'm using Sendgrid API to send an email message over HTTP via PHP. This is my code:

<?php
$url = 'https://api.sendgrid.com/';
$user = 'USER';
$pass = 'PASSWORD';
$params = array(
    'api_user'  => $user,
    'api_key'   => $pass,
    'to'        => 'TARGET',
    'subject'   => 'Kami Menanti Anda',
    'from'      => 'noreply@kompetisiindonesia.com',
  );
  $params['html'] = 'html message';
  $params['text'] = $params['html'];
$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);

But I get this error message:

Notice: Use of undefined constant CURL_SSLVERSION_TLSv1_2 - assumed 'CURL_SSLVERSION_TLSv1_2' in /opt/lampp/htdocs/oprek/sendgrid/sendviahttp.php on line 28

Does anybody know what's happening?

查看全部
doumeng1897
doumeng1897
2015/04/14 17:34
  • curl
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

4个回复