Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple GET request with PHP cURL to send SMS text message

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.

like image 984
JnBrymn Avatar asked Dec 21 '22 21:12

JnBrymn


1 Answers

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.

like image 128
Rytis Avatar answered Dec 28 '22 05:12

Rytis