Showing posts with label SMS. Show all posts
Showing posts with label SMS. Show all posts

Monday, March 1, 2010

Send SMS function using PHP

What are usually need to make a sms;



This is a simple function to send sms using php script.


<?php

function PostToHostSMS($host, $port, $username, $password, $data_to_send)
{
$dc = 0;
$bo ="--------453534534534536";

$fp = fsockopen($host, $port, $errno, $errstr);
if (!$fp) {
echo "errno: $errno \n";
echo "errstr: $errstr\n";
return $result;
}

fputs
($fp, "POST / HTTP/1.1\r\n");
if ($username != "") {
$auth = $username . ":" . $password;
echo "auth: $auth\n";
$auth = base64_encode($auth);
echo "auth: $auth\n";
fwrite
($fp, "Authorization: Basic " . $auth . "\r\n");
}
fputs
($fp, "User-Agent: NowSMS PHP Script\r\n");
fputs
($fp, "Accept: */*\r\n");
fputs
($fp, "Content-type: multipart/form-data; boundary=$bo\r\n");

foreach($data_to_send as $key=>$val) {
$ds =sprintf("%s\r\nContent-Disposition: form-data;
name=\"%s\"\r\n%s\r\n"
,$bo,$key,$val);
$dc += strlen($ds);

}
$dc += strlen($bo)+3;
fputs
($fp, "Content-length: $dc\r\n");
fputs
($fp, "\r\n");
fputs
($fp, "This is a MIME message\r\n\r\n");

foreach($data_to_send as $key=>$val) {
$ds =sprintf("%s\r\nContent-Disposition: form-data;
name=\"%s\"\r\n%s\r\n"
,$bo,$key,$val);
fputs
($fp, $ds );
}
$ds = $bo."--\r\n" ;
fputs
($fp, $ds);

$res = "";

while(!feof($fp)) {
$res .= fread($fp,1);
}
fclose
($fp);


return $res;
}

?>