Below is my code, after searching and working all night, I finally figured how to make it send an sms. The problem is that I can’t leave spaces in the body message and it does not display the value of $smsmessage.
extract($_POST);
$smsmessage1 = "This is the sms that will be sent";
$smsmessage = urlencode($smsmessage1);
//set POST variables
$url = 'http://www.mysmsgateway.com/bulksms/bulksms.php?username=myemail@domain.com&password=123456789&message=$smsmessage&mobile=2348035081907&sender=Boss';
$fields = array();
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
The above codes sends the message but will output $smsmessage instead of fetching the value of $smsmessage from above.
You’re using single quotes for specifying
$url, which means the$smsmessagewon’t be interpreted.You’ll need to use double quotes instead:
For more information about the difference between the two, see PHP: Strings from the PHP manual.