
Данный скрипт был написан в целях тестирования. Как и ожидалось, отправителя русскими буквами указать нельзя, urlencode не помогает. Подставляйте свои логин и пароль вместо [removed] и наслаждайтесь.
HTML-форма для отправки (верстка на базе bootstrap):
<!DOCTYPE html>
<html>
<body>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!-- jQuery library -->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Отправка СМС</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<center><h1>Отправка СМС</h1></center>
<div class="container" style="min-height: 500px">
<div class="starter-template">
<form action="sms.php" method="post" role="form" id="search-form">
<div class="form-group">
<label class="">Номер получателя (в формате +79... , можно несколько через запятую):</label> <input
type="text" name="receiver" class="form-control">
</div>
<div class="form-group">
<label class="">Количество частей:</label> <input type="text"
name="max_parts" value="3" class="form-control">
</div>
<div class="form-group">
<label class="">Текст сообщения:</label>
<textarea width="60" height="10" name="message" class="form-control"></textarea>
</div>
<div class="form-group">
<label class="">Кем подписать (только лат. буквы):</label> <input
type="text" name="originator" class="form-control">
</div>
<div class="form-group">
<label class="">Flash:</label> <input
type="text" name="flash" class="form-control" value="0">
</div>
<input type="submit" value="Послать" class="btn btn-default">
</form>
</div>
</div>
</body>
</html> |
<!DOCTYPE html>
<html>
<body>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!-- jQuery library -->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Отправка СМС</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<center><h1>Отправка СМС</h1></center>
<div class="container" style="min-height: 500px">
<div class="starter-template">
<form action="sms.php" method="post" role="form" id="search-form">
<div class="form-group">
<label class="">Номер получателя (в формате +79... , можно несколько через запятую):</label> <input
type="text" name="receiver" class="form-control">
</div>
<div class="form-group">
<label class="">Количество частей:</label> <input type="text"
name="max_parts" value="3" class="form-control">
</div>
<div class="form-group">
<label class="">Текст сообщения:</label>
<textarea width="60" height="10" name="message" class="form-control"></textarea>
</div>
<div class="form-group">
<label class="">Кем подписать (только лат. буквы):</label> <input
type="text" name="originator" class="form-control">
</div>
<div class="form-group">
<label class="">Flash:</label> <input
type="text" name="flash" class="form-control" value="0">
</div>
<input type="submit" value="Послать" class="btn btn-default">
</form>
</div>
</div>
</body>
</html>
Собственно, скрипт:
<?php
$login="[removed]";
$password="[removed]";
$rus="5";
$script_url="http://www.smstraffic.ru/multi.php";
$content_header="application/x-www-form-urlencoded;charset=utf-8";
$receiver = $_POST["receiver"];
$max_parts = $_POST["max_parts"];
$message = urlencode($_POST["message"]);
$originator = $_POST["originator"];
$flash = $_POST["flash"];
$data = "login=".$login."&password=".$password."&want_sms_ids=1&phones=".$receiver."&message=".$message."&max_parts=".$max_parts."&rus=".$rus."&originator=".$originator."&flash=".$flash;
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: ".$content_header."\r\n",
'method' => 'POST',
'content' => $data
)
);
$context = stream_context_create($options);
$result = file_get_contents($script_url, false, $context);
if ($result === FALSE) { echo "not sent"; }
$str = htmlentities($result, ENT_QUOTES, 'UTF-8');
var_dump($str);
?> |
<?php
$login="[removed]";
$password="[removed]";
$rus="5";
$script_url="http://www.smstraffic.ru/multi.php";
$content_header="application/x-www-form-urlencoded;charset=utf-8";
$receiver = $_POST["receiver"];
$max_parts = $_POST["max_parts"];
$message = urlencode($_POST["message"]);
$originator = $_POST["originator"];
$flash = $_POST["flash"];
$data = "login=".$login."&password=".$password."&want_sms_ids=1&phones=".$receiver."&message=".$message."&max_parts=".$max_parts."&rus=".$rus."&originator=".$originator."&flash=".$flash;
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: ".$content_header."\r\n",
'method' => 'POST',
'content' => $data
)
);
$context = stream_context_create($options);
$result = file_get_contents($script_url, false, $context);
if ($result === FALSE) { echo "not sent"; }
$str = htmlentities($result, ENT_QUOTES, 'UTF-8');
var_dump($str);
?>
Не забудьте спрятать скрипт за пароль на своем веб сервере.
Полезная документация:
SMS traffic API