We all started sending forms to an email using a simple kind of mailto where we placed destination server and email address as hidden fields in a form. Nowadays, this is dangerous, when spammer's robots scan pages for URLs and emails. However, Mailto was simple to use and everybody could integrate it.
This Mailto.cfc for CF 7+ still does the same but with many details: Firstly, you can place the form fields like destination email and server, in fact, any hidden form field in an encrypted form. MailTo.cfc tries to use AES, if not available, it uses CF's standard algorithm.
Once the form will be submitted, Mailto.cfc automatically decrypts them and creates a nice html table in the mail to the destination address and relocates the surfer to a success or a failure page.
Secondly, all the usual Mailto functions are there: Which fields are required? What is the mail's subject? You can suppress fields from being displayed in the mail, you can sort the fields in the mail and you can also prefix the data table in the mail with any text you want.
You can even use this Mailto.cfc as an en-/de-cryptor only to transport hidden fields from page to page. You just disable the automatic location change.
Thirdly, it can also generate a captcha functionality: It poses simple arithmetic questions with a verbal addendum to make it (almost) impossible for robots to understand the question. Example:
What's the triple fold of 12+23
The captcha function randomly chooses one of three question you provide and generates the addition multiplied by the position of the question in the list + 1. Example:
"What's twice as much as,Calculate the triple of,Give us the four-fold of"
The Captcha feature chooses one and therefore a question could be:
"Give us the four-fold of 12+9" // the correct answer will be 84
It includes the hashed result in an encrypted hidden field, so the captcha is completely context-free. The salt will make it even more impossible that anyone can cheat the captcha by means of examining the html code. If any robot will be able to understand what "triple fold" means, just create a more verbose question which a human still understands and there you go again secured.
If captcha fields are presend, Mailto.cfc will automatically verify the result and in case of difference redirect to the error page.
Any field causing problems will be reported to the errorurl in a list to the url parameter missing_fields=. So you can report to the user which field(s) are missing or whether the captcha result was wrong.
Installation is easy, just copy the Mailto.cfc into ColdFusion's CustomTag directory. Then create a simple wrapper.cfm to be the target of a form's action parameter (since you cannot direct the form to a cfc directly).
Then you make your forms ... like this:
--- <cfscript> mt = CreateObject ("component", "Mailto"); mt.Init (key = application.mailto_key, salt = application.mailto_salt); </cfscript>
Now, you can encrpyt any field's value before placing it in the form, Mailto.cfc will later recognise the presence of the encryption.
<cfform action="/mailto_wrapper.cfm" method="post"> <cfinput type="hidden" name="server" value="#mt.GetEncryptedField("server", "smtp.youdoamin.com")#"> <cfinput type="hidden" name="sendto" value="#mt.GetEncryptedField("sendto", "info@yourdomain.com")#"> <cfinput type="hidden" name="resulturl" value="#mt.GetEncryptedField("resulturl", "http://www.mindpower.com")#"> <cfinput type="hidden" name="errorurl" value="#mt.GetEncryptedField("errorurl", "http://www.blick.ch")#"> <cfinput type="hidden" name="pretext" value="These are your form data"> <cfinput type="hidden" name="suppress" value="do_mail"> <cfinput type="hidden" name="required" value="#mt.GetEncryptedField("required", "firstname,sex")#"> <cfinput type="hidden" name="subject" value="Form data delivery"> ...
if you want to use the Captcha feature ...
<cfset temp = mt.GetCaptchaData ("What's twice as much as,Calculate the triple of,Give us the four-fold of")>
#ListFirst (temp)# <cfinput name="captcha_answer" type="text" title="Enter the result of the question"> <cfinput type="hidden" name="captcha_result" value="#ListRest(temp)#"><br>
... <cfinput type="submit" name="do_mail" value="Submit"> </cfform>
---
The minimum mailto_wrapper.cfm is always the same and is very simple. Of course, you can enhance the wrapper in any way you need.
--- <cfscript> mt = CreateObject ("component", "Mailto"); mt.Init (key = application.mailto_key, salt = application.mailto_salt); mt.Deliver(); // mt.Deliver(no_redir = "true"); // this one only decodes the form's members </cfscript> ---
This is it. Quite easy, isn't it?
|