Twilio SMS and ColdFusion

Here’s an example of how you can send an SMS using Twilio and ColdFusion:

<cfset accountSid = "Your Twilio Account SID">
<cfset authToken = "Your Twilio Auth Token">
<cfset twilioNumber = "Your Twilio Phone Number">
<cfset recipientNumber = "The Phone Number You Want to Text">
<cfset messageBody = "The text message you want to send">

<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/#accountSid#/Messages.json" method="post" result="httpResponse">
  <cfhttpparam type="header" name="Authorization" value="Basic #ToBase64(accountSid & ":" & authToken)#">
  <cfhttpparam type="formfield" name="From" value="#twilioNumber#">
  <cfhttpparam type="formfield" name="To" value="#recipientNumber#">
  <cfhttpparam type="formfield" name="Body" value="#messageBody#">
</cfhttp>

<cfif httpResponse.StatusCode EQ 201>
  <p>SMS sent successfully!</p>
<cfelse>
  <p>Failed to send SMS. Response from Twilio: #httpResponse.FileContent#</p>
</cfif>
In this example, you'll need to replace the placeholder values for accountSid, authToken, twilioNumber, recipientNumber, and messageBody with your actual Twilio account information and the SMS message you want to send. The cfhttp call to the Twilio API will send the SMS, and the cfif block will check the response from Twilio to see if the SMS was sent successfully.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *