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?
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Comments
Ben Dowling replied on Mon, 2008/11/17 - 12:04pm
Dave Newton replied on Mon, 2008/11/17 - 4:18pm
in response to: coderholic
Ben Dowling 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!
Dave Newton replied on Mon, 2008/11/17 - 5:33pm
in response to: coderholic
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
d. potter 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.).