Sendsms.php doesn't work with nowsms cloud?

Sendsms.php doesn't work with nowsms cloud? SearchSearch

SMS & MMS Technical Forum » NowSMS Cloud Edition (Product Support Only) » Sendsms.php doesn't work with nowsms cloud? « Previous || Next »
Author Message
Nigel
New member
Username: Nigel

Post Number: 1
Registered: 07-2017
Posted on Sunday, July 09, 2017 - 05:33 pm:   

hi,

i have used nowsms gateway before with sendsms.php, but i cannot figure out how to use it with cloud version.

i think maybe it is port number? cloud version only supports https://, does not support http://

i tried port number 443, but cannot make it work.

cheers,

nigel
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 8170
Registered: 10-2002
Posted on Sunday, July 09, 2017 - 06:37 pm:   

Hi nigel,

We have a few web pages that we still need to update.

Basically, the old sendsms.php used raw plain text socket i/o, and does not understand SSL/TLS encryption as required for https:// requests.

sendsms.php is a rather simple script...so we changed the way it issues HTTP requests so that it will work for http:// or https://

This does require a minor parameter change...the first two parameters for the old version were host name or IP, followed by the port number. In the new version, instead these are combined into a single parameter, which is the URL of the NowSMS server (e.g., http://127.0.0.1:8800 or https://sample.smshosts.com/

 
<?php

function SendSMS ($hostUrl, $username, $password, $phoneNoRecip, $msgText) {

// Parameters:
// $hostUrl – URL of the NowSMS server (e.g., http://127.0.0.1:8800 or https://sample.smshosts.com/
// $username – “SMS Users” account on the NowSMS server
// $password – Password defined for the “SMS Users” account on the NowSMS Server
// $phoneNoRecip – One or more phone numbers (comma delimited) to receive the text message
// $msgText – Text of the message

$postfields = array('Phone'=>"$phoneNoRecip", 'Text'=>"$msgText");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $hostUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
// curl_setopt($ch, CURLOPT_VERBOSE, true);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
// curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // change to 1 to verify cert
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);

return $result;

}


// This code provides an example of how you would call the SendSMS function from within
// a PHP script to send a message. The response from the NowSMS server is echoed back from the script.

$x = SendSMS('https://sample.smshosts.com/', 'username', 'password', '+44999999999', 'Test Message');
echo $x;

?>


text/plain
sendsms.php.txt (1.6 k)


-bn

Bryce Norwood
Now SMS/MMS Support


P.S. - I should mention there are a few lines commented out. In this version, the SSL certificate is not checked for validity. We still need to do testing to determine the best way to do this in PHP.
Nigel
New member
Username: Nigel

Post Number: 2
Registered: 07-2017
Posted on Monday, July 10, 2017 - 12:22 pm:   

perfect!

Add Your Message Here, or click here to create a new discussion topic.
Post:
Bold text Italics Underline Create a hyperlink Insert a clipart image
Posting Information:
This is a private posting area. Only registered users and moderators may post messages here.
Click here to create an account.
Username:
Password:
Options: Automatically activate URLs in message
Action:

Login Login / Register Logout Logout Search Last 30 Days Topics Topics