2015-04-14 17:34
浏览 311

Sendgrid PHP使用未定义的常量CURL_SSLVERSION_TLSv1_2

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

$url = '';
$user = 'USER';
$pass = 'PASSWORD';
$params = array(
    'api_user'  => $user,
    'api_key'   => $pass,
    'to'        => 'TARGET',
    'subject'   => 'Kami Menanti Anda',
    'from'      => '',
  $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_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
// print everything out

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?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • douxianji6181 2015-04-15 14:10

    It looks like you might have an outdated build of CURL installed on your machine.

    CURL_SSLVERSION_TLSv1_2 (integer) Available since PHP 5.5.19 and 5.6.3

    打赏 评论
  • dsfsw1233 2016-08-04 20:58

    Depending on your situation, you can try using the integer that represents the constant. In our case (CentOS6, with IUS PHP 5.3.23), the constant was not there, but the following worked just fine..

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "");
    curl_setopt($ch, CURLOPT_SSLVERSION, 6);
    打赏 评论
  • duanmu1736 2018-07-06 08:45
    if ( ! defined('CURL_SSLVERSION_TLSv1_2')) {
            define('CURL_SSLVERSION_TLSv1_2', 6);

    Add above code before

    curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
    打赏 评论
  • doy51723 2019-06-05 11:07

    Also, check the namespace your code is running in. If you have a TYPO3-command-controller, it`s code will run in \TYPO3 - namespace. Constants defined in the regular normal namespace have to be prepended with a backslash then, to be evaluated correctly.

    打赏 评论

相关推荐 更多相似问题