I'm creating quick web app that needs to send a php-created message from within php code. cURL is apparently the tool for the job, but I'm having difficulty understanding it enough to get it working.
The documentation for the API I'm dealing with is here. In particular I want to use the simple GET-based sms notification documented here. The latter resource states that the GET API is simply:
http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber={PHONENUMBER}&Message={MESSAGE}&LicenseKey={LICENSEKEY}
And indeed, if I type the following URL into a browser, I get the expected results:
http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber=15362364325&Message=mymessage&LicenseKey=2134234882347139482314987123487
I am now trying to create the same affect within php. Here is my attempt:
<html>
<body>
<?php
$num = '13634859126';
$message = 'some swanky test message';
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber=".urlencode($num)."&Message=".urlencode($message)."&LicenseKey=2345987342583745349872");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
</body>
</html>
My other PHP webpages work fine, so I know php and apache are all set up correctly. But When I point my browser at the above page, I get no message on my phone. Can anybody show me what I'm doing wrong?
Note: all numbers are faked... as you might have suspected.
Do you really need CURL? You simply use PHP's file_get_contents($url)
, which will do a GET request and will return response value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With