https://api.twilio.com/2010-04-01/Accounts/{Account SID}/Messages.json
<form role="form" name="frmTwilioSMSScriptBased" id="frmTwilioSMSScriptBased" class="mt-4" novalidate autocomplete="off">
<div class="form-row">
<div class="form-group col">
<label for="fName" id="fnameLabel" class="formLabel">first name</label>
<div class="input-group">
<span class="input-group-addon"><i class="faw faw-user-tie"></i></span>
<input type="text" name="fname" id="fname" class="form-control" placeholder="first name">
</div>
<div class="formError" id="fnameError">Please enter your first name (up to 21 letters, spaces, apostrophes and dashes allowed)</div>
</div>
</div>
<div class="form-row">
<div class="form-group col">
<label for="lname" id="lnameLabel" class="formLabel">last name</label>
<div class="input-group">
<span class="input-group-addon"><i class="faw faw-user-tie"></i></span>
<input type="text" name="lname" id="lname" class="form-control" placeholder="last name">
</div>
<div class="formError" id="lnameError">Please enter your last name (up to 21 letters, spaces, apostrophes and dashes allowed)</div>
</div>
</div>
<div class="form-row">
<div class="form-group col">
<label for="phone" id="phoneLabel" class="formLabel">phone</label>
<div class="input-group">
<span class="input-group-addon">i class="faw faw-phone-glyphicon"</i></span>
<input type="text" class="form-control" placeholder="phone" aria-label="Phone Number" name="phone" id="phone">
</div>
<div class="formError" id="phoneError">Please enter your phone number</div>
</div>
</div>
<div class="form-row">
<div class="form-group col">
<label for="message" id="messageLabel" class="formLabel">message</label>
<textarea class="form-control" name="message" placeholder="your message"</textarea>
<div class="formError" id="messageError">Please enter your message</div>
</div>
</div>
<div class="form-row">
<div class="form-group col" id="frmMessage"></div>
</div>
<div class="form-row">
<div class="form-group col">
<button class="btn btn-primary" type="button" id="btnSubmitSMS"><i class="faw faw-send">Request Information</button>
</div>
</div>
</form>
<cftry>
<cfscript>
if (NOT IsDefined("Form.FName") OR NOT IsDefined("Form.LName") OR NOT IsDefined("Form.Phone") OR NOT IsDefined("Form.Message") OR NOT IsValid("regex",Form.FName,"^[a-zA-Z' -]{1,21}$") OR NOT IsValid("regex",Form.LName,"^[a-zA-Z' -]{1,22}$") OR NOT IsValid("telephone",Form.Phone)) {
abort;
}
VARIABLES.tmi = {};
VARIABLES.tmi.fromPhone = Application.TwilioFrom;
VARIABLES.tmi.toPhone = Form.Phone;
VARIABLES.tmi.message = 'Message from ' & GetSafeHTML(Form.FName) & ' ' & GetSafeHTML(Form.LName) & ': ' & GetSafeHTML(Form.Message);
VARIABLES.tmi.TwilioSMSResource = Application.TwilioSMSResource;
VARIABLES.tmi.TwilioUserName = Application.TwilioUserName;
VARIABLES.tmi.TwilioPassword = Application.TwilioPassword;
VARIABLES.tmi.StatusCallback = Application.TwilioStatusCallback;
VARIABLES.post = Application.TwilioSMSService.sendSMSTextCFScript(VARIABLES.tmi);
if (VARIABLES.post.statusCode EQ '201 Created') {
writeOutput(1);
}
else {
writeOutput(VARIABLES.post.statusCode);
}
</cfscript>
<cfcatch type="Any">
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
<cfcomponent>
<cfscript>
public struct function sendSMSTextCFScript(required struct tmi) {
cfhttp(method="POST", charset="utf-8", url="#ARGUMENTS.tmi.twilioSMSResource#", username="#ARGUMENTS.tmi.twilioUserName#", password="#ARGUMENTS.tmi.twilioPassword#", result="status") {
cfhttpparam(name="From", type="formfield", value="#ARGUMENTS.tmi.fromPhone#");
cfhttpparam(name="To", type="formfield", value="#ARGUMENTS.tmi.toPhone#");
cfhttpparam(name="Body", type="formfield", value="#ARGUMENTS.tmi.message#");
cfhttpparam(name="StatusCallback", type="formfield", value="#ARGUMENTS.tmi.statusCallback#");
}
return status;
}
</cfscript>
</cfcomponent>
<cfcomponent>
<cffunction name="sendSMSText" access="public" returntype="struct" hint="This method is used to send a SMS message using Twilio">
<cfargument name="tmi" type="struct" required="yes" hint="This argument expects a structure of information to include in a text message">
<--- Credit for this code can be attributed to Ben Nadel's post at https://www.bennadel.com/blog/1966-sending-sms-text-messages-from-twilio-using-coldfusion.htm. His example accounted for the majority of this sample code. Thank you Ben! --->
<cfhttp
result="status"
method="post"
url="#ARGUMENTS.tmi.twilioSMSResource#"
username="#ARGUMENTS.tmi.twilioUsername#"
password="#ARGUMENTS.tmi.twilioPassword#">
<cfhttpparam
type="formfield"
name="From"
value="#ARGUMENTS.tmi.fromPhone#"
/>
<cfhttpparam
type="formfield"
name="To"
value="#ARGUMENTS.tmi.toPhone#"
/>
<cfhttpparam
type="formfield"
name="Body"
value="#ARGUMENTS.tmi.Message#"
/>
<cfhttpparam
type="formfield"
name="StatusCallback"
value="#ARGUMENTS.tmi.StatusCallback#"
/>
</cfhttp>
<cfreturn status>
</cffunction>
</cfcomponent>