PHP code to send a sms via API to a phone list

Asked

Viewed 109 times

1

Please would like a light for the code below, as it connects in an SMS sending API, but would like to send to more numbers at the same time, but the code below sends to a single number.

<?php
    $ch = curl_init();

    $data = array('key'         => 'CHAVE API', 
                  'type'        => '9',
                  'number'      => '199999999',
                                    'msg'         => 'MENSAGEM DE TEXTO');

    curl_setopt($ch, CURLOPT_URL, 'http://api.deenvio.com.br/send');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $res    = curl_exec ($ch);
    $err    = curl_errno($ch);
    $errmsg = curl_error($ch);
    $header = curl_getinfo($ch);

    curl_close($ch);

    print_r($res); 
?>  
  • What would the API be? They probably have this described in their documentation.

  • face vc have to see the documentation of the API if it supports sending mass messages (Bulk). Case no support has to make a loop and send one message at a time

1 answer

0

Try this

<?php
$ch = curl_init();

$lista_telefone[] = '888888888';
$lista_telefone[] = '999999999';

$data = [];
foreach($lista_telefone as $indice => $numero){
    $array_numero = array('key'         => 'CHAVE API', 
                        'type'        => '9',
                        'number'      => $numero,
                        'msg'         => 'MENSAGEM DE TEXTO');
    array_push($data, $array_numero);

}


curl_setopt($ch, CURLOPT_URL, 'http://api.deenvio.com.br/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$res    = curl_exec ($ch);
$err    = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);

curl_close($ch);
print_r($res); 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.