Send Email with cf_sebForm

I saw two blog entries recently (by Ben Nadel and by Mark Mazelin) on generic solutions to automatically send email with a form. This is a common need for a lot of web sites, especially on contact forms. These entries motivated me to show how cf_sebForm handles this.

Very quickly, I think cf_sebForm offers an of being generically useful beyond sending email. But even if that is the only use, I believe it is still as good as any solution otherwise available.

In previous entries, I have mostly focused on using cf_sebForm as a front-end for a CFC. It does, however, have other options. For example, it can also handle email processing without needing any separate code.

Here is an example:

<cf_sebForm
mailserver="mail.example.com"
email="test@example.com"
emailfrom="robot@example.com"
subject="Example.com Contact Form"
forward="contact_thanks.cfm"
>

<cf_sebField name="name" label="Name">
<cf_sebField type="email" name="email" label="E-Mail" required="true">
<cf_sebField name="comments" label="Comments/Questions" type="textarea">
<cf_sebField type="submit/cancel" label="Submit,Cancel">
</cf_sebForm>

This will produce a basic contact form with three fields, that can be skinned or styled to look how you want (and is very close to the code for my contact form).

It will send a basic email to the email address listed in the "email" attribute. Before doing so, however, it will do client-side and server-side validations on the form.

It is important to note that none of the attributes of this form get written as form fields (hidden or otherwise), so spammers can't change their values and use your form to send spam to others.

If you are worried about getting spam yourself, you can easily drop in my SpamFilter component to filter for spam. Assuming you have SpamFilter loaded into "Application.SpamFilter", simply add a filter="#Application.SpamFilter#" attribute to cf_sebForm and it is all set up.

SpamFilter and cf_sebForm aren't actually tied together, I just wrote SpamFilter to follow the guidelines required for a component passed to the "filter" attribute of cf_sebForm (which I will cover in a future entry).

All of this makes it very easy to use cf_sebForm to send email.

The cf_sebForm (tag docs) custom tag is part of the sebtags custom tag set which is open source and free for any use.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.