What if your contact form fails?

Contact form

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?

More articles in Blog archive or elsewhere
Advertisement

13 Comment(s)

Bill Beckelman

Bill Beckelman 16 Nov 2008 #

Janko,

This is a cool idea that probably not too many people have considered. You might want to encode the subject and body with the JavaScript function encodeURIComponent. Here is an article about it: email.about.com/cs/standards/a/mailto_js.htm.

Best Regards,
Bill Beckelman

Cohen

Cohen 16 Nov 2008 #

Great idea,

But since the server side (sending the email) is probably the one breaking, should'nt it be better practive to let it catch it and let it generate the mailto uri, instead of the javascript generating it?
And I definitely agree with Bill about the Uri encoding... I don't know how forgiving mailto: handlers are, regarding spaces and special characrers?
Nice article,

Regards
Cohen

Janko

Janko 16 Nov 2008 #

Bill, thanks for reminding me, definitively should be encoded.

Cohen, it might be one of the solutions if you're using ASP.NET, yes. But this one is applicable to any technology. I don't know how it can be handled in, let's say, PHP - But JavaScript will work Wink

Max

Max 16 Nov 2008 #

Pretty clever actually, becasue most people wont bother rewriting the message so saving what they have written is a bonus. like it!

Ben Tortora

Ben Tortora 17 Nov 2008 #

So simple I wish I thought of it myself.

So good it deserved a twitter!

Thanks!

Nebbercracker

Nebbercracker 17 Nov 2008 #

Very interesting indeed.  Good one!

Coderholic

Coderholic 17 Nov 2008 #

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/

Kris

Kris 17 Nov 2008 #

That's a good idea and would make many a user much happier than retyping their messages (I know from experience that I wouldn't bother).

You can also include the message they tried to send (everything they entered actually) in your error logs. That way, even if they don't resend it (which they still may not), you still get the message and can hopefully figure out why it caused the error so that you can prevent it next time.

Janko

Janko 17 Nov 2008 #

Thanks guys!

Coderholic: if you decide to store messages in db you can also create a windows service that will send messages from the queue. If you have a simple contact form, your solution might be enough. But if you have more complex situation like multiple recipients, this will ensure that everyone receive their message.

Kris: Yes, error log is a must!

Daniel

Daniel 17 Nov 2008 #

This  could end up frustrating the user even worse.  First, it assumes a lot about the client machine - that it has an offline client, that the user is not on  a public terminal, etc.  Many users don't have an offline client (this wouldn't work for gmail users without the google toolbar, etc).  But even if that's not an issue,  suppose it failed because of an error at your mail server.  The user would fail the first form, then send from outlook, and get a bounced email there as well.

A better solution, IMO, would be to design your server code so that it, not the user, takes responsibility for handling messages with errors.  Logging using a logging framework is probably the best way- you could route errors to a log file/event log/sql/etc.  If using .NET, it's also possible to configure SMTP to simply drop the email in a "pickup directory", from which the SMTP service can pick it up and handle errors gracefully (ie log them or put them in an errors directory).  

msdn.microsoft.com/en-us/library/ms164241.aspx





Janko

Janko 17 Nov 2008 #

Daniel: Yes, like Kris and Coderholic said, this can be another alternative (and error log should be implementer in either way). I wanted this to be a simple trick that can improve the user experience. If one wants to do more complex handling of this problem, no doubt the server side should take the responsibility for handling this.

Thinkpad T60

Thinkpad T60 18 Nov 2008 #

Good idea to solve the problem that store the message in a database on the server.  

Thanks for share.

Santhos Webdesign

Santhos Webdesign 21 Nov 2008 #

Some time ago I discovered that the contactform on our site submitted the message to an e-mail address that wasn't working anymore (I lost the domain in a strange way...)... How about that!

I found out in my site statistics that the form was filled in twice but I never received the messages... Those could have been 2 potential clients...

Comments are closed
via Ad Packs
9292