This topic is locked
[SOLVED]

 SMS Api

1/26/2016 8:41:12 AM
PHPRunner General questions
S
snuffi01 author

Hi,
I'm trying to set up a way to send sms through an PHPR site.

The API witch i'm trying to use is https://www.nexmo.com/
I store the "api key", "api secret" in user table.

In my table for new sms there are 3 columns:

"sms_to_number"

"sms_sender_number"

"sms_message"
On the Add page (and Before record added) i have the following code:



$url = 'https://rest.nexmo.com/sms/json?'; . http_build_query([

'api_key' =>$_SESSION["sms_api_key"],

'api_secret' =>$_SESSION["sms_api_secret"],

'to' =>$values["sms_to_number"],

'from' =>$values["sms_sender_number"],

'text' =>$values["sms_message"]

]);
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);


My problem is that the url never seems to be performed.
If i echo $url i can see that the url is right (i can even test the url in browser window and the sms is sent).
I guess that i made something wrong in above code?

Admin 1/26/2016

As a first step - make sure this code is executed. It might be located in the part of event that never runs.
Once you are sure it is executed - check for any PHP errors. You can also create a test PHP file hardcoding all values and running it manually to see if it works this way.

S
snuffi01 author 1/27/2016

Thanks,
Tried to make an php file, hordcoded with all values (on another webserver).

When running the php file i get this:



Parse error: syntax error, unexpected '[', expecting ')' in C:\wamp\www\folder\test.php on line 2
Admin 1/27/2016

What version of PHP your server runs?

S
snuffi01 author 1/27/2016



What version of PHP your server runs?


My php version is 5.6.0

S
snuffi01 author 1/27/2016

As a workaround i also tried to use cURL instead (as stated here : https://developers.nexmo.com/Quickstarts/sms/send/)

Dont know if its possible at all to use cURL in this way...
When trying the code:



curl 'https://rest.nexmo.com/sms/json'; \

-d api_key=$_SESSION["sms_api_key"] \

-d api_secret=$_SESSION["sms_api_secret"] \

-d to=$values["sms_to_number"] \

--data-urlencode . $values["sms_message"] \

-d from=$values["sms_sender_number"]


I get this error inside the PHPRunner program:

syntax error, unexpected ''https://rest.nexmo.com/sms/js'; (T_CONSTANT_ENCAPSED_STRING) in line 2

Admin 1/27/2016

Running cURL from the command line is more complicated than using PHP curl_ functions.
The reason I asked about PHP version is that your sample uses syntax (array in square brackets) that is available in PHP 5.4 or higher. And error message said

unexpected '['


Anyway, you need to modify this sample code till it runs in your test PHP file and then use in PHPRunner.

S
snuffi01 author 1/28/2016

Made it work at last <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=78663&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

After adding this to my php code i got som usefull information what went wrong:



if(!curl_exec($curl)){

die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));


Problem was Certificate issue, added the row:



CURLOPT_SSL_VERIFYPEER => 0,



To temporary go around the problem and see some result !