-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsendsms.php
32 lines (28 loc) · 997 Bytes
/
sendsms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
use IP1\RESTClient\Core\Communicator;
use IP1\RESTClient\SMS\OutGoingSMS;
require_once('vendor/autoload.php');
if (!preg_match('/(07|\+46)[0-9 ]{1,15}/', $_POST['recipeint'])) {
header("Location:/");
}
if (strlen($_POST['text']) > 160) {
header("Location:/");
}
$config = json_decode(file_get_contents('config.json'), true);
$api = new Communicator($config['account'], $config['token']);
$prefix = '07';
$alternativePrefix = '+467';
$cellphone = $_POST['recipeint'];
if (substr($cellphone, 0, strlen($prefix)) == $prefix) {
$cellphone = substr($cellphone, strlen($prefix));
$cellphone = "467" . $cellphone;
}
if (substr($cellphone, 0, strlen($alternativePrefix)) == $alternativePrefix) {
$cellphone = substr($cellphone, strlen($alternativePrefix));
$cellphone = "467" . $cellphone;
}
$cellphone = str_replace(" ", "", $cellphone);
$sms = new OutGoingSMS('iP1Demo', $_POST['text']);
$sms->addNumber($cellphone);
$api->add($sms);
header("Location:/?sent=success");