Forums

Send SMS (API Gateway) using cURL

terrance85 28 Nov, 2011
Hi folks,

I'm hoping to integrate sms reminders for bookings made through a form on my website.
The SMS service company have provided the following template:
<?php
// Authorisation details
$uname = "youremailaddress";
$pword = "yourpassword";

// Configuration variables
$info = "1";
$test = "0";

// Data for text message
$from = "Jims Autos";
$selectednums = "440000000000";
$message = "Test with an ampersand (&) and a £5 note";
$message = urlencode($message);

// Prepare data for POST request
$data = "uname=".$uname."&pword=".$pword."&message=".$message."&from=". $from."&selectednums=".$selectednums."&info=".$info."&test=".$test; 

// Send the POST request with cURL
$ch = curl_init('http://www.txtlocal.com/sendsmspost.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); //This is the result from Textlocal
curl_close($ch);
?>

Firstly, I'm not at all sure how to integrate this code into my form - i.e. what goes where in the cURL configuration. I'm a novice, but did know the change "youremailaddress" to my email address etc :p

Also, I need the code to be dynamic and use information submitted to the form by the user - mobile phone number, customer name and booking date/type. So that the sms would be sent to the mobile number entered in the form and the sent sms would read something like:

"Hello {customer_name}. Your car is due for {booking_type} on {booking_date}...."

I also want to schedule the sms, which I believe can be done, to be sent 3 days before the booking date - as a booking reminder basically. I know this is asking a lot, if I just get the code in and working I'll be delighted.

Looking forward to any responses 😀 ,

Cheers

terrance85
GreyHead 29 Nov, 2011
Hi terrance,

Which version of ChronoForms are you using? You can find the version from Site Admin | Extensions | Install/Uninstall | Components in Joomla! 1.5 or Site Admin | Extensions | Extension Manager | Manage in Joomla! 1.6.

You can start with the article here on doing something very similar with ChronoForms v3.

The timed email is not built-in to ChronoForms but you can probably do it using a cron job set up on your webserver.

Bob
terrance85 30 Nov, 2011
Hi Bob,

Thanks for the reply.

I checked my chronoman version and it looks like I'm running 3.1 RC5.5 (04 Aug 2009).
I think I'm due an update - was looking here:
http://www.chronoengine.com/downloads/chronoforms/chronoforms-j1/85-component.html
Wasn't sure what one to go for. I looks like J1.5_V4_RC2.0 will not update my version but is a standalone version that I could import my existing forms into?

I had already looked at the link you suggested but unfortunately it didnt help much.
I'm using a company called Textlocal for the sms service and they don't provide much support for integrating sms with an existing site via API. I tried to follow the guide but as I dont have a proper understanding of what I'm doing with PHP etc, there were too many differences between your example and my provider for me to get things up and running. Textlocal have this page http://www.textlocal.com/developers/docs/ but, as I say, I dont know how to use this with CURL. I'm not sure if I have to use the 'field names' or if it's just the 'extra fields data' I need to fill in. Also not sure what to put in the 'CURL params' 😟

Help would be much appreciated. Keep up the good work! Mon the chrono!!!

A
GreyHead 01 Dec, 2011
Hi terrance85,

You should probably upgrade to CFv3.2 There is no particular advantage in going to CFv4 except as a step on the way to Joomla! 1.6/1.7.

I think that the cURL plug-in will do what you need here. If you look at the sample PHP code for the Send SMS API here then you can see the variables that are needed:
$data = "uname=".$uname."&pword=".$pword."&message=".$message."&from=". $from."&selectednums=".$selectednums."&info=".$info."&test=".$test;

// Send the POST request with cURL
$ch = curl_init('http://www.txtlocal.com/sendsmspost.php');

In Chronoforms this gives you first the Target URL
http://www.txtlocal.com/sendsmspost.php
and second the variables list
uname=
pword=
message=
from=
selectednums=
info=
test=

Each of these either needs to be matched to a form input, or have a fixed value assigned to it.

Bob



Bob
This topic is locked and no more replies can be posted.