Using curl functions in php to send sms for smaple sms gateway
Saturday, November 8, 2008 11:42This is a sample code assuming we have a sms gateway with name smsgateway.co.cc. We have take a sample
$curlPost = 'Mobile_No=9000099119&Type=SMS&Message="This is a test message"'; //we have to pass the mobile number and message as argument to the url. $LOGINURL = "http://smsgateway.co.cc/UserMiscellaneousMT.asp"; //This url will be provided by our gateway $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)"; //setting the browser agent as Firefox $ch = curl_init(); // initiate a curl function c url_setopt($ch, CURLOPT_URL,$LOGINURL); //set the url to be used curl_setopt($ch, CURLOPT_USERAGENT, $agent); //set the browser curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2); //set the maxmium time to execute curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // accept the responce after the execution curl_setopt($ch, CURLOPT_POST, 1); // set the post method for passing variables to the server curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); //assigning the post values $result = curl_exec ($ch); //executing with the above set options and catching the values in a variable curl_close ($ch); // closing the connection echo $result; // printing the result.
CURL_INIT():-
The curl_init() function returns a Curl instance for us to use in later functions, and you should always store it for later. It has just one optional parameter: if you pass a string into curl_init(), it will automatically use that string as the URL to work with. In the script above, we use curl_setopt() to do that for clarity, but it is all the same.
Curl_setopt():-
Curl_setopt() takes three parameters, which are the Curl instance to use, a constant value for the setting you want to change, and the value you want to use for that setting. There are a huge number of constants you can use for settings, and many of these are listed shortly. In the example we use CURLOPT_URL:- which is used to set the URL for Curl. CURLOPT_USERAGENT:- which is used to set browseragent for Curl. CURLOPT_CONNECTTIMEOUT:- which is used to set the MAX ececution tiem for Curl. CURLOPT_RETURNTRANSFER:- which is used to set the Returntransfer enable for Curl. CURLOPT_POST:- which is used to set the method of posting the variables for Curl. CURLOPT_POSTFIELDS:- which is used to set the variables for Curl.
curl_exec():-
Calling curl_exec() means, We finished setting our options and ready do it, and you need to pass precisely one parameter: the Curl resource to use. The return value of curl_exec() is true/false by default.
curl_close():-
The final function, curl_close(), takes a Curl resource as its only parameter, closes the Curl session, then frees up the associated memory.

Using curl functions in php to send SMS via SMS gateway | CLD Tutorials says:
December 14th, 2008 at 8:10 am
[...] View tutorial Tutorial Stats : 1 views Rate Tutorial : (No Ratings Yet) Loading … DiggStumbleDel.icio.usFloatBumpMixxRedditzaBoxother [...]
edward says:
February 2nd, 2009 at 7:20 pm
does dis work.. can i put any mobile num.. will i receive the message?..
PHP_Starter says:
February 2nd, 2009 at 11:51 pm
This works if you use any SMS Gateway.
jesse says:
May 11th, 2009 at 1:52 am
please suggest any free sms gateway
james g says:
July 1st, 2009 at 12:10 am
Thank you so much for this! Now I need to get Adobe Photoshop.. :p
Arif says:
March 5th, 2010 at 6:11 am
Great script
neha says:
March 26th, 2010 at 3:27 am
We used this script to send smses and it works great.. But we need to schedule the smses i.e. select when to send, a particular date and time. Can this be done using curl functions?
PHP_Starter says:
March 26th, 2010 at 10:01 pm
It depends. I have to know what os ur using to answer. conatct me sathyendrav a t gmail.com
habeeb says:
March 29th, 2010 at 3:22 am
can we send messages to many at a time?r there any free sms gateways?
and finally can we get back the reply to our email accounts?
PHP_Starter says:
March 29th, 2010 at 6:17 am
Hi,
Sending messages to many at a time can be done using a loop or it can also be done if the SMSGateway API supporst it. I did not come across any free SMS Gateway. and for your final question. yes you can get the reply on your email accounts if the SMSGateway supports the reply.
PHP_Starter says:
March 31st, 2010 at 12:26 am
According to ur mail u are using windows xp server. Try the following command to schedule the task.
schtasks /create /tn “Drupal Cron Job” /tr “C:\PROGRA~1\MOZILL~1\firefox.exe” http://www.example.com/cron.php /sc hourly
Note:- There are many free task scheduling softwares available in the internet, Just google for them.
Thanks & Regards,
Sathyendra V.
PHP_Starter says:
March 31st, 2010 at 12:29 am
Hi Neha,
For your problem of space getting removed, send me the code you are using so that i can help you further on this.
Thanks & Regards,
Sathyendra V
Spatan says:
May 12th, 2010 at 1:44 pm
Hi, great post. please i working on sms application using zend framewrok. I use curl to send my sms , but unfortuantely it wont work if i integrate it with zend. But if i use the script ordinarily with php it works.
I have tried all i could to troubleshoot but my effort prove abortive..
Here is my script. if you can assist me http:www.visualprotocol.com/sms.html.
Please trace the code to where i implement curl to send my sms. I will be glad if you can assis me. I dont know what im doing wrong
Spatan says:
May 12th, 2010 at 1:57 pm
please use this http://www.visualprotocol.com/sms.php