Send SMS From Contact Form
Does anyone know of a sms / text messaging service script that works well with the Contact Form Solution Pack. I have my site setup to send to multiple recipients selected by the user. The form works perfectly. I now want to send these messages to multiple phone numbers via sms.
Here is the code I have so far.
<?php require_once('./WA_Globals/WA_Globals.php');?>
<?php require_once("./WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("./WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php require_once("./WA_Universal_Email/mail_PHP.php"); ?>
<?php require_once("./WA_Universal_Email/MailFormatting_PHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$varCatSelect_get_email_addresses = "' '";
if (isset($_GET['varCatSelect'])) {
$varCatSelect_get_email_addresses = $_GET['varCatSelect'];
}
$varLocSelect_get_email_addresses = "' '";
if (isset($_GET['varLocSelect'])) {
$varLocSelect_get_email_addresses = $_GET['varLocSelect'];
}
mysql_select_db($database_Connection, $Connection);
$query_get_email_addresses = sprintf("SELECT * FROM advertisers WHERE catagory= %s AND location= %s", GetSQLValueString($varCatSelect_get_email_addresses, "text"),GetSQLValueString($varLocSelect_get_email_addresses, "text"));
$get_email_addresses = mysql_query($query_get_email_addresses, $Connection) or die(mysql_error());
$row_get_email_addresses = mysql_fetch_assoc($get_email_addresses);
$totalRows_get_email_addresses = mysql_num_rows($get_email_addresses);
?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$WAFV_Redirect = "";
$_SESSION['WAVT_contact_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_POST["Contact_Name"]))?$_POST["Contact_Name"]:"") . "",true,1);
$WAFV_Errors .= WAValidateEM(((isset($_POST["Email_address"]))?$_POST["Email_address"]:"") . "",true,2);
$WAFV_Errors .= WAValidateRQ(((isset($_POST["Comments"]))?$_POST["Comments"]:"") . "",true,3);
$WAFV_Errors .= WAValidateLE(((isset($_POST["Security_code"]))?strtolower($_POST["Security_code"]):"") . "",((isset($_SESSION["captcha_1"]))?strtolower($_SESSION["captcha_1"]):"") . "",true,4);
$WAFV_Errors .= WAValidateLE(((isset($_POST["Security_question"]))?strtolower($_POST["Security_question"]):"") . "",((isset($_SESSION["random_answer"]))?strtolower($_SESSION["random_answer"]):"") . "",true,5);
$WAFV_Errors .= WAValidateRX(((isset($_POST["addblock"]))?$_POST["addblock"]:"") . "","/^$/i",false,6);
$WAFV_Errors .= WAValidateRX(((isset($_POST["seconddblock"]))?$_POST["seconddblock"]:"") . "","/^$/i",false,7);
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"contact");
}
}
?>
<?php
if ((($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST))) {
//WA Universal Email object="mail"
//Send Loop Once Per Entry
$RecipientEmail = "".($WAGLOBAL_Contact_Email_To) ."";include("./WA_Universal_Email/WAUE_contact_1.php");
//Send Mail All Entries
if ("index.php"!="") {
header("Location: thankyou.php");
}
}
?>
<?php
// This script sends sms to multiple recipients
$URN = "urn:notify.soap.thesmsgatewaycompany.net";
$WSDL="http://thesmsgatewaycompany.net/pmws/services/TxTMessageService?wsdl";
$encoding = SOAP_DEFAULT_ENCODING;
//SOAP elements (don‟t edit, and case sensitive!)
$SOAP_ACTION = "sendMessage";
$CTUSERNAME = "Username";
$CTPASSWORD = "Password";
$CTNICKNAME = "nickname";
$DESTINATION = "destination";
$MESSAGE = "message";
$RECIPIENT = "recipients";
$ADMINEMAIL = "adminEmail";
$SUBJECT = "subject";
$USER_ID = "USERNAME"; //your username at CellTrust
$NICKNAME = "NICKNAME"; //your nickname at Celltrust
$PASSWORD = "password"; //your password at Celltrust
//create user and password SOAP header elements
$UserHdr = new SoapHeader( $URN, $CTUSERNAME, $USER_ID, false);
$PassHdr = new SoapHeader( $URN, $CTPASSWORD, $PASSWORD, false);
//create SOAP body elements, add your destination phone number, and message here
$dialstring = array(array("deliveryType" => 0, "destination" => "14805551212", "firstName" => "John", "lastName" => "Doe", "carrierId" => "19"),
array("deliveryType" => 0, "destination" => "14805551213", "firstName" => "Judy", "lastName" => "Doe", "carrierId" => "19"),
array("deliveryType" => 0, "destination" => "14805551214", "firstName" => "Test", "lastName" => "Doe", "carrierId" => "19"));
$bodymulti = array($CTNICKNAME => $NICKNAME, $SUBJECT => "Test SMS Message", $MESSAGE => "Test SMS Message Multiple recipients", $RECIPIENT => $dialstring, $ADMINEMAIL = "");
//create SOAP client
$client = new SoapClient($WSDL, array('trace' => 1, 'exceptions' =>0));
//set SOAP headers
$client->__setSoapHeaders(array($UserHdr, $PassHdr));
//call web service single sms
$result = $client->__call("sendMessage", $bodymulti, NULL);
//very usefull for debug purposes
//show what was requested
var_dump($client->__getLastRequest());
//show gateways response
var_dump($client->__getLastResponse());
?>
This following code copied from above contains a sample array of multiple phone recipients which I will pull from the database the same way I have done so with the catagory and locations in this example but Im not sure if these scripts are conflicting or what is the best way to make sure that they will work together. Or, if someone knows of a sms service or script that will work better. Ideally, I would like this script to work as I have already set up an account with this sms service for trial purposes.
Any help with this is greatly appreciated. Thank you