What If Your Contact Form Fails?

Did you ever think about it? Someone types the message, clicks on send and gets the error message like "Something went wrong. Sorry...". Ok, what now? How TF can I send you a message?

Contact form is often the only way you can communicate with someone. People just don't like to expose their email addresses just like that. But having a contact form means that it might fail at some point. Your SMTP server could be down or your application could just stop working. It happened so many times.

So what can you do?

Well, instead of showing seamless error message and informing users that your application broke, you can offer them an alternative. Instead of showing a message "An error occurred. Your email cannot be sent", you can show "An error occurred and your email cannot be sent. However, you can still contact me on my@email.com". Much better, isn't it?

Better? Yes, but not good enough

What if someone just typed several paragraphs? There is a small chance that he/she will type it again unless it is something seriously important. There is very simple trick to avoid this problem. Literally, copy the text user typed and paste it into the email link.

If you have these two input fields (beside other) in your contact form:

<input type="text" id="subject">
<input type="text" id="message">

you can create email link dynamically with this simple JavaScript code:

<script type="text/javascript">
var subject = document.getElementById("subject").value;
var msg = document.getElementById("message").value;
var link = document.getElementById("emailme");

link.href="mailto:my@email.com?subject=" + subject + "&body=" + msg;
</script>

And your error message could look like this:

<div id="errorMessage">Error Occured. Please contact me on <a id="emailme" href="my@email.com">my@email.com</a></div>

Pretty simple, but do you know any other way to do this? How would you solve this problem?

References
0

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

coderholic replied on Mon, 2008/11/17 - 12:04pm

An alternative approach is to store the message in a database on the server. I've put details and code samples into a blog post: www.coderholic.com/handling-contact-form-failure/

newton_dave replied on Mon, 2008/11/17 - 4:18pm in response to: coderholic

I kinda thought the point was what to do if the app fails... like the message wasn't stored in the DB.

coderholic replied on Mon, 2008/11/17 - 5:29pm in response to: newton_dave

I've never had a contact form fail for any other reason than the email wasn't sent, because email is the thing that is out of your control.

If you're having problems with your database a failed contact form is the least of your worries!

newton_dave replied on Mon, 2008/11/17 - 5:33pm in response to: coderholic

I agree, but that's not the point.

Bruno Borges replied on Mon, 2008/11/17 - 5:44pm

Why people still use "Contact Forms" when there are lots and lots of ways to provide an email to people contact you directly?

By the way, what is the difference between a Contact Form and a mailto:contact@mycompany.com? Stop coding contact forms, please. :-)

Bruno Borges

dpotter replied on Mon, 2008/11/17 - 11:26pm

interesting. if your users are willing to e-mail you directly and have javascript anyways, does this count as free spam filtering? ;)

by that i mean maybe you could wire this up directly to the original form and bypass the submit altogether, it works better than submit anyways... POST is pesky, and the trip through the web server and the bowels of the e-mail architecture (that you hopefully never have to manage) is fraught with peril. do what the code suggests and provide a link only after certain fields are populated, but skip the web server and validate that e-mail (a bit) on the way. you get to use free e-mail spam filtering technology (and not blame the spam on the web developer)... i'm seeing nothing but WIN here.

thanks guys!

Philippe Lhoste replied on Fri, 2008/11/21 - 12:58pm in response to: bruno borges

Bruno, among other things, contact forms can be useful to avoid spreading e-mails over the Net, making easy preys for spam bots.

Beside, mailto: isn't failsafe either: what if you are at a Web cafe and click on such link? At best there is no e-mail client available and it will fail, at worst it will launch the local client (probably Outlook Express...) and user is stuck with a client not configured for her.

mailto: links also fail if the user uses only a Web e-mail client...

Unlike you, I see this protocol as quite dead alas, killed by spammer among other problems.

Contact forms are quite convenient, because they are just a click away and easy to fill in. The only culprit, beside needing server-side code, is that users might hesitate to provide an e-mail address for reply... (or can mistype it, etc.).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.