<!--- Param the URL variables. ---> <cftry> <cfparam name="URL.id" type="numeric" default="0" /> <cfcatch> <cfset URL.id = 0 /> </cfcatch> </cftry> <!--- Query for the given ID. ---> <cfquery name="qMessage" dbtype="query"> SELECT message FROM APPLICATION.Messages WHERE id = <cfqueryparam value="#URL.id#" cfsqltype="CF_SQL_INTEGER" /> </cfquery> <!--- Check to see if the passed ID matches a message that we have defined in our application. ---> <cfif qMessage.RecordCount> <!--- Use the ColdFusion CFMail tag to send the text message using the celluar carrier's mobile phone email address. ---> <cfmail to="0123456789@vtext.com" from="9876543210@vtext.com" subject=""> <!--- Send the text part. ---> <cfmailpart type="text" >#qMessage.message#</cfmailpart> </cfmail> <!--- Now that the message has been sent, we want to select a random interval of time only after which we can then send out another text message. We don't want to send them out too often, or she will suspect something. Let's add between 2 and 8 hours. We are going to create the time span with minutes (not hours) to get a more random distribution. ---> <cfset APPLICATION.Settings.NextMessage = ( Now() + <!--- Randomly pick time interval. ---> CreateTimeSpan( 0, 0, RandRange( (2 * 60), (8 * 60) ), 0 ) ) /> <!--- Add this message ID to the array of previous messages so that we don't have to mentally keep track of which messages have already been sent. ---> <cfset ArrayAppend( APPLICATION.Settings.PrevMessages, URL.id ) /> <!--- We only want to keep track of the last three message. If we have more than that, we need to pop one off the top. ---> <cfif (APPLICATION.Settings.PrevMessages.Size() GT 3)> <!--- Pop the first one off. ---> <cfset ArrayDeleteAt( APPLICATION.Settings.PrevMessages, 1 ) /> </cfif> <!--- At this point, our application settings have been updated. Now, we just need to update our data file in case our application crashes or has to be reinitialized. Convert the settings to WDDX. ---> <cfwddx action="CFML2WDDX" input="#APPLICATION.Settings#" output="REQUEST.SettingsData" /> <!--- Write the app settings to disk. ---> <cffile action="WRITE" file="#APPLICATION.Settings.FilePath#" output="#REQUEST.SettingsData#" /> </cfif> <cfoutput> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Text Message Confirmation</title> </head> <body> <!--- Check to see if a message was found. ---> <cfif qMessage.RecordCount> <p> The following message has been sent: </p> <blockquote> #qMessage.message# </blockquote> <cfelse> <p> <em>The given message could not be found</em>. </p> </cfif> </body> </html> </cfoutput>