Dengan mengandalkan website yang memfasilitasi user untuk mengirimkan SMS secara gratis ini akan sangat berharga. Anda tidak perlu membuat sebuah aplikasi SMS Gateway sendiri untuk membuat fasilitas SMS untuk keperluan apapun.
Berikut website penyedia SMS gratis yang bisa disuplay dari websitenya. https://www.vivacom.bg/
<?php
// CAUTION - VIVACOM PHONE NUMBERS ONLY!!!
class VivaSMS {
private $browser;
private $session_id;
function __construct($username = '', $password = '') {
if(empty($username)) {
throw new InvalidArgumentException('User name is empty.');
}
if(empty($password)) {
throw new InvalidArgumentException('Password is empty.');
}
$this->browser = 'Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0';
$postdata = 'temp=login.html&forgottenpass=1&username='.$username.'&password='.$password;
//login
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.vivacom.bg/online/cgi-bin/web2sms.cgi');
curl_setopt($ch, CURLOPT_USERAGENT, $this->browser);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.vivacom.bg', 'Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
curl_close($ch);
unset($ch);
//extract session id
if(preg_match('/"0; URL=.*?&ls=(.*?)">/is', $result, $matches)) {
$this->session_id = $matches[1];
} else {
throw new UnexpectedValueException('Cannot retrieve session ID.');
}
}
public function sendSms($phone = '', $message = '') {
if(empty($phone)) {
throw new InvalidArgumentException('Phone number is empty.');
}
if(!preg_match('/^08d{8}$/', $phone)) {
throw new InvalidArgumentException('Invalid phone format! Expected format: 08хххххххх.');
}
if(empty($message)) {
throw new InvalidArgumentException('SMS message is empty.');
}
if(100 < strlen($message)) {
throw new InvalidArgumentException('SMS message length cannot exceeds 100 symbols.');
}
if(0 >= $this->getRemainingMsgs()) {
throw new RuntimeException('Your daily SMS limit (20 messages per day) has been reached.');
}
$message = urlencode($message);
$postdata = 'temp=send_sms.html&page=1&control=1&type=&ls='.$this->session_id.'&lphone='.substr($phone, 1).'&loginuser='.$phone.'<phone='.substr($phone, 1).'&phones='.$phone.'&msgLen='.strlen($message).'&det='.$message;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.vivacom.bg/online/cgi-bin/web2sms.cgi');
curl_setopt($ch, CURLOPT_USERAGENT, $this->browser);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.vivacom.bg', 'Referer: https://www.vivacom.bg/online/cgi-bin/web2sms.cgi?temp=send_sms.html&ls='.$this->session_id, 'Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
curl_close($ch);
unset($ch);
if(preg_match('/"0; URL=(.*?)">/is', $result, $matches)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $matches[1]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
unset($ch);
if(preg_match('/не е абонат на VIVACOM/', iconv('cp1251', 'UTF-8', $result))) {
throw new UnexpectedValueException('Мобилен номер '.$phone.' не е абонат на VIVACOM!.');
}
}
}
public function getRemainingMsgs() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.vivacom.bg/online/cgi-bin/web2sms.cgi?temp=send_sms.html&ls='.$this->session_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
unset($ch);
if(preg_match('/Остават ви (d+) съобщения за деня./is', iconv('cp1251', 'UTF-8', $result), $matches)) {
return $matches[1];
}
return -1;
}
}
// Example usage
$username = 'YOUR_VIVACOM_USERNAME';//Register here if you don't have VIVACOM account: http://www.vivacom.bg/online/cgi-bin/PhoneBill.cgi
$password = 'YOUR_VIVACOM_PASSWORD';
$phone = 'VIVACOM_PHONE_NUMBER';
$message = 'Hi tester';//up to 100 chars, up to 20 free SMS messages per day
try {
$sms = new VivaSMS($username, $password);
$sms->sendSms($phone, $message);
//echo $sms->getRemainingMsgs();
} catch (Exception $ex) {
echo $ex->getMessage();
}
EmoticonEmoticon