html - php code to send sms without the manual entry of mobilenumber and message inside the code -
<?php //please enter details $user="user_name"; //your username $password="your_password"; //your password $mobilenumbers="0123456789"; //enter mobile numbers comma seperated $message = "demo sms"; //enter message $senderid="demo"; //your senderid $messagetype="n"; //type of message $url="http://sms.mavyah.com/webservicesms.aspx"; //domain name: domain name replace domain $message = urlencode($message); $ch = curl_init(); if (!$ch){die("couldn't initialize curl handle");} $ret = curl_setopt($ch, curlopt_url,$url); curl_setopt ($ch, curlopt_post, 1); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, 2); curl_setopt ($ch, curlopt_postfields, "user=$user&passwd=$password&mobilenumber=$mobilenumbers&message=$ message&sid=$s enderid&mtype=$messagetype"); $ret = curl_setopt($ch, curlopt_returntransfer, 1); //if behind proxy please uncomment below line , provide proxy ip port. // $ret = curl_setopt($ch, curlopt_proxy, "proxy ip address:port"); $curlresponse = curl_exec($ch); // execute if(curl_errno($ch)) echo 'curl error : '. curl_error($ch); if (empty($ret)) { // kind of error happened die(curl_error($ch)); curl_close($ch); // close curl handler } else { $info = curl_getinfo($ch); curl_close($ch); // close curl handler //echo "<br>"; echo $curlresponse; //echo "message sent succesfully" ; } ?>
i have written php code sending sms message. code uses sms country api. in code, seen above, have include $mobilenumbers
tells whom message should sent. need changes how send message recipient without mentioning number in code. i.e., when html form filled receipient , message fields should taken input $mobilenumber
, $message
in code. should not enter number , message manually inside code.
i assume getting values form of sort, this:
<form name="form" action="" method="post"> <input type="text" name="mobilenumbers" id="mobilenumbers" value="mobile number"> <input type="text" name="message" id="message" value="message"> </form>
then need fetch values form php code:
function sendsms($mobilenumbers, $message) { // validation if ( ! is_numeric($mobilenumbers) ) { return; } $message = urlencode($message); $user="your_username"; //your username $password="your_password"; //your password $senderid="demo"; //your senderid $messagetype="n"; //type of message $url="http://sms.mavyah.com/webservicesms.aspx"; //domain name: domain name replace domain $ch = curl_init(); if (!$ch){die("couldn't initialize curl handle");} $ret = curl_setopt($ch, curlopt_url,$url); curl_setopt ($ch, curlopt_post, 1); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, 2); curl_setopt ($ch, curlopt_postfields, "user=$user&passwd=$password&mobilenumber=$mobilenumbers&message=$ message&sid=$s enderid&mtype=$messagetype"); $ret = curl_setopt($ch, curlopt_returntransfer, 1); // if behind proxy please uncomment below line , provide // proxy ip port. // $ret = curl_setopt($ch, curlopt_proxy, "proxy ip address:port"); $curlresponse = curl_exec($ch); // execute if(curl_errno($ch)) echo 'curl error : '. curl_error($ch); if (empty($ret)) { // kind of error happened die(curl_error($ch)); curl_close($ch); // close curl handler } else { $info = curl_getinfo($ch); curl_close($ch); // close curl handler //echo "<br>"; echo $curlresponse; //echo "message sent succesfully" ; } } // call function values provided form sendsms($_post('mobilenumbers'), $_post('message'));
wrap code never should change in function , call function values form. should validate user data, have added simple check phone number, value isn't number function fail silently.
Comments
Post a Comment