Simple GET request with PHP cURL to send an SMS text message

I am creating a fast web application that should send a php message from PHP code. cURL seems to be a tool to work with, but it's hard for me to understand enough to make it work.

The documentation for the API I'm dealing with is here . In particular, I want to use the simple GET-based SMS notification registered here . The last resource claims that the GET API is simple:

http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber={PHONENUMBER}&Message={MESSAGE}&LicenseKey={LICENSEKEY}

And indeed, if I type the following URL in the browser, I will get the expected results:

http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber=15362364325&Message=mymessage&LicenseKey=2134234882347139482314987123487

Now I am trying to create the same effect in 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>

- PHP , , php apache . , . - , ?

: ... .

+3
4

CURL? PHP file_get_contents($url), GET .

+9

, , cURL . , .

$result=curl_exec($ch);
$curlerrno = curl_errno($ch);
curl_close($ch);
print $curlerrno;

: libcurl-errors

- cURL:

curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($ch,CURLOPT_TIMEOUT,5);
+1

, URL-, , , . , , ,

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // tell the return not to go to the browser

     $output = curl_exec($ch); // point the data to a variable

     print "<br />"; // output the variable
     print $output;
     print "<br />";

, :

     curl_setopt($ch, CURLOPT_INTERFACE, "93.221.161.69"); // telling the remote system where to send the data back
     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); // pretend you are IE/Mozilla in case the remote server expects it
     curl_setopt($ch, CURLOPT_POST, 1); // setting as a post
0
source

Just replace it with
Phone Number = $ Num

curl_setopt ($ ch, CURLOPT_URL, " http://sms2.cdyne.com/sms.svc/SimpleSMSsend?PhoneNumber= " .urlencode ($ num). "& Message =". urlencode ($ message) "& LicenseKey = 2345987342583745349872 ".);

0
source

Source: https://habr.com/ru/post/1775025/


All Articles