Toma Tomov
Toma Tomov

Reputation: 1654

How to send sms via php when i have the API link

I have a link from the via which I can send sms. It works when I put it in the address bar and fill the required get params and press enter. But how can I load it in the middle of controller action (the framework is Yii2 if that matters) ? I tried with mail() but couldn't reach any result. The link is like below:

http://sms.***********.com/httpApi/Send.aspx?phone=359.........&body=message&username=xxx&password=xxx

Can I make it with plain php or I have to it via javascript ? Thank you in advance!

Upvotes: 1

Views: 939

Answers (2)

helpdoc
helpdoc

Reputation: 1990

cURL allows transfer of data across a wide variety of protocols, and is a very powerful system. It's widely used as a way to send data across websites, including things like API interaction and oAuth. cURL is unrestricted in what it can do, from the basic HTTP request, to the more complex FTP upload or interaction with an authentication enclosed HTTPS site. We'll be looking at the simple difference between sending a GET and POST request and dealing with the returned response, as well as highlighting some useful parameters.

$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'YOUR API URL',
    CURLOPT_USERAGENT => 'cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);

The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close().

Upvotes: 2

pgndck
pgndck

Reputation: 328

You should use сURL.

$query = http_build_query([
 'phone' => '359.........',
 'body' => 'message',
 'username' => 'xxx',
 'password' => 'xxx'
]);

$c = curl_init();
curl_setopt($c , CURLOPT_URL , 'http://sms.***********.com/httpApi/Send.aspx/?' . $query);
curl_exec($c); 
curl_close($c);

Upvotes: 1

Related Questions