简体   繁体   中英

How send sms in php?

How do I fix this issue? I cannot send sms on my work.

$ch = curl_init(); //curl()
$parameters = array(
  'apikey' => '8a6bb687750b59d8f099cb489b43c256', //Your API KEY
  'number' => '09096817174',//number
  'message' => 'I just sent my first message with Semaphore', //message
  'sendername' => 'SEMAPHORE');
curl_setopt( $ch, CURLOPT_URL,'https://semaphore.co/api/v4/messages');
curl_setopt( $ch, CURLOPT_POST, 1 );

//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );

How do I fix this issue? I have my apikey in semaphore.

Hey i tried this code and print output

    <?php
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

$ch = curl_init();
$parameters = array(
    'apikey' => '8a6bb687750b59d8f099cb489b43c256', //Your API KEY
    'number' => '0987654321',//for testing no 
    'message' => 'I just sent my first message with Semaphore',
    'sendername' => 'SEMAPHORE'
);
curl_setopt( $ch, CURLOPT_URL,'https://semaphore.co/api/v4/messages' );
curl_setopt( $ch, CURLOPT_POST, 1 );

//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );

// Receive response from server
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close ($ch);

//Show the server response

echo $output;

i got return output

"message_id":73840803,

"status":"Pending",

Using live key and test and try to hit same code check status is pending to received

This worked for me

 $ch = curl_init(); 
 $parameters = array(
          'apikey' => '8a6bb687750b59d8f099cb489b43c256', 
          'number' => '9000000000',
          'message' => 'I just sent my first message with Semaphore', 
          'sendername' => 'SEMAPHORE'
          );
curl_setopt( $ch, CURLOPT_URL,'https://semaphore.co/api/v4/messages' );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );

$result = curl_exec($ch);
print_r($result);
if (curl_errno($ch)) {
    $error_msg = curl_error($ch);
    print_r($error_msg);
}
curl_close($ch);
exit;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM