Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use of undefined constant CURLAUTH_BEARER - assumed 'CURLAUTH_BEARER'

New Contributor

I have copied the PHP code from your website and whenever I run it, I get the the error :-

"Use of undefined constant CURLAUTH_BEARER - assumed 'CURLAUTH_BEARER'", here is the code here below please help.


$service_plan_id = "acbb90139d844ac985e72d7760xxxxxx"; //ServiceplanID
$bearer_token ="-Uri";

//Any phone number assigned to your API
$send_from = "447537404817";
//May be several, separate with a comma ,
$recipient_phone_numbers = "+277202xxxx";
$message = "Test message to {$recipient_phone_numbers} from {$send_from}";

// Check recipient_phone_numbers for multiple numbers and make it an array.
if(stristr($recipient_phone_numbers, ',')){
$recipient_phone_numbers = explode(',', $recipient_phone_numbers);
$recipient_phone_numbers = [$recipient_phone_numbers];

// Set necessary fields to be JSON encoded
$content = [
'to' => array_values($recipient_phone_numbers),
'from' => $send_from,
'body' => $message

$data = json_encode($content);

$ch = curl_init("{$service_plan_id}/batches");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_XOAUTH2_BEARER, $bearer_token);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);

if(curl_errno($ch)) {
echo "Curl error: " . curl_error($ch);
} else {
echo $result;


Community Manager
Community Manager

Hello, thank you for reaching out!

Can you let us know which versions of PHP/cURL you have installed? The CURLAUTH_BEARER constant has been available since PHP 7.3.0 and cURL 7.61.0, so you may be running into issues if you are using a prior version of either.


Thanks again!

Sam Williams, Sinch Documentation Engineer

New Contributor

Hi Sam

I'm using cURL 7.83.1

Community Manager
Community Manager

Hello again!


Thank you for your response. I've reached out to someone on our SMS team to see if they can provide any more insight into this issue. In the meantime, you can try to use the code sample provided in our API reference (you can set the language to PHP using the drop-down list above the code sample). That sample makes use of the libcurl library, and does not reference the CURLAUTH_BEARER constant. Finally, do you know which version of PHP you are using? That may also be contributing to your issue.


Thanks again!

Sam Williams, Sinch Documentation Engineer