微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Sendgrid PHP使用未定义的常量CURL_SSLVERSION_TLSv1_2

我正在使用Sendgrid API通过PHP通过HTTP发送电子邮件.这是我的代码

<?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);

但我收到此错误消息:

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

有人知道发生了什么吗?

解决方法:

看起来您的计算机上可能安装了过时的CURL版本.

CURL_SSLVERSION_TLSv1_2 (integer) Available since PHP 5.5.19 and 5.6.3

http://php.net/manual/en/curl.constants.php

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐