Send SMS with PHP
Send SMS using HTTP with PHP
PHP : API DOCUMENTATION
- Create group with PHP
- Get group field list with PHP
- Add a field to a group with PHP
- Delete a field from a group with PHP
- Delete a contact from a group
- Assing country to e group with PHP
- Get group contact list with PHP
- Add contact to a group with PHP
- Modify contact of a group with PHP
- Delete contact of a group with PHP
Send SMS with PHP
Este método le permite enviar SMS a un destinatario utilizando PHP. Enviar un SMS con PHP es tan sencillo como enviar el origin, destino y el mensaje a enviar a través de una petición a nuestra API.
<?
$class="sms";
$method="sendsms";
$user="user";
$password="password";
$from="Afilnet";
$to="34600000000";
$sms="sms+test";
$scheduledatetime="";
$output="";
$result = file_get_contents("https://www.afilnet.com/api/http/?class=".$class."&method=".$method."&user=".$user."&password=".$password."&from=".$from."&to=".$to."&sms=".$sms."&scheduledatetime=".$scheduledatetime."&output=".$output);
?>
<?
$url = "https://www.afilnet.com/api/http/";
$fields = array(
"class" => urlencode("sms"),
"method" => urlencode("sendsms"),
"user" => urlencode("user"),
"password" => urlencode("password"),
"from" => urlencode("Afilnet"),
"to" => urlencode("34600000000"),
"sms" => urlencode("sms+test"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<?
$url = "https://www.afilnet.com/api/basic/";
$fields = array(
"class" => urlencode("sms"),
"method" => urlencode("sendsms"),
"from" => urlencode("Afilnet"),
"to" => urlencode("34600000000"),
"sms" => urlencode("sms+test"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERPWD, $user.":".$password);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 401)
{
// LOGIN ERROR
} else {
// SUCCESS LOGIN
}
?>
<?
# This example requires nusoap
require_once('nusoap.php');
$class="sms";
$method="sendsms";
$user="user";
$password="password";
$from="Afilnet";
$to="34600000000";
$sms="sms+test";
$scheduledatetime="";
$output="";
# Create SOAP Client
$soapclient = new soapclient('https://www.afilnet.com/api/soap/index.php?wsdl');
# Call to method
$result = $soapclient->call($user, $password, $class, $method, '{"from":"'.$from.'","to":"'.$to.'","sms":"'.$sms.'","scheduledatetime":"'.$scheduledatetime.'","output":"'.$output.'"}');
?>
Parameter | Description | Compulsory / Optional |
---|---|---|
class=sms | Class requested: Class to which the request is made | Compulsory |
method=sendsms | Class method requested: Method of the class to which the request is made | Compulsory |
user | User and e-mail of your Afilnet account | Compulsory |
password | Password of your Afilnet account | Compulsory |
from | Sender | Compulsory |
to | Mobile phone number of the recipient | Compulsory |
sms | SMS message to be sent | Compulsory |
scheduledatetime | Sending date and time in yyyy-mm-dd hh:mm:ss format | Optional |
output | Output format of the result | Optional |
When you make requests you will receive the following fields:
- status
-
result (if status=success), here you will receive the following values:
- messageid
- credits
- error (if status=error), here you will receive the error code
The possible error codes are listed below
Code | Description |
---|---|
MISSING_USER | User or email not included |
MISSING_PASSWORD | Password not included |
MISSING_CLASS | Class not included |
MISSING_METHOD | Method not included |
MISSING_COMPULSORY_PARAM | Compulsory parameter not included |
INCORRECT_USER_PASSWORD | Incorrect user or password |
INCORRECT_CLASS | Incorrect class |
INCORRECT_METHOD | Incorrect method |
NO_ROUTE_AVAILABLE | There are no available paths for the indicated destination |
NO_CREDITS | Your balance is insufficient |
Parameters:
- class : sms
- method : sendsms
- user : user
- password : password
- from : Afilnet
- to : 34600000000
- sms : sms+test
- scheduledatetime :
- output :
Request:
https://www.afilnet.com/api/http/?class=sms&method=sendsms&user=user&password=password&from=Afilnet&to=34600000000&sms=sms+test&scheduledatetime=&output=