【发布时间】:2015-06-20 10:46:26
【问题描述】:
我正在使用 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);
但我收到此错误消息:
注意:使用未定义的常量 CURL_SSLVERSION_TLSv1_2 - 假定 'CURL_SSLVERSION_TLSv1_2' 在 /opt/lampp/htdocs/oprek/sendgrid/sendviahttp.php 在第 28 行
有人知道发生了什么吗?
【问题讨论】:
-
正如@Matt Bernier 所说,您无需升级 PHP 即可将 CURLOPT_SSLVERSION 设置为 CURL_SSLVERSION_TLSv1_2。使用 6 代替 CURL_SSLVERSION_TLSv1_2。欲了解更多信息read this。 TLS 1.2 适用于我的 PHP 5.2.17 和 cURL 7.24.0