Welcome to WebmasterWorld Guest from

Forum Moderators: open

Online form help needed please.

7:08 pm on Mar 16, 2009 (gmt 0)

5+ Year Member

Hi all

I've been asked to set up an online form for a side project at work, and unfortunately, I only have a very small understanding of javascript.

The form needs to send data directly to a specified email address rather than bring up an email box, which is what it's doing at the moment due to the mailto: command. Here's the HTML part of the form (I've had to take out my email address for privacy reasons):

<form name="omaform" action="mailto:email@address.com?subject="From the suggestion box">
Your Name: (optional)<br>
<input type="text" size="26" name="Name"><br><br>
Your Suggestion:<br>
<textarea name="Suggestion" rows="8" cols="20">
<input type="submit" value="Submit Suggestion">

Can anyone provide me with the .js code or anything else I'd need to have the data from the form sent directly to the email? It's meant to be for anonymous submissions so obviously having the email edit box pop up isn't any good!

The site this will be on is hosted on a Streamline server if that's any help!

3:45 am on Mar 17, 2009 (gmt 0)

5+ Year Member

You don't need any JavaScript to submit an email via the mailto: specifier, but you will need to specify the method (POST) and the encoding type (text/plain), e.g.

<form name="x" method="POST" action="mailto:your_addy@..." enctype="text/plain">

I strongly suggest, however, that you use a server-side script using Perl, PHP, ASP, Java, etc that accepts the form and processes the email for you rather than exposing the address, giving direct access to a form with your email address (or your client's email!) and allowing chaos to ensue.

7:54 am on Mar 17, 2009 (gmt 0)

5+ Year Member

Thanks for the reply Blang. I've tried the code you mentioned, but that still just brings up the empty email box. I had a feeling I'd need a server-side script to do what I wanted but again, I know very little about this... *rueful grin*
2:21 pm on Mar 17, 2009 (gmt 0)

5+ Year Member

In reviewing your markup, I noticed a problem. You have an unterminated string:
<form name="omaform" action="mailto:email@address.com?subject="From the suggestion box">

Notice that? You start to wrap the mailto: string in "double quotes", then open the subject string in "double quotes" as well. You need to do something like this instead:

<form name="omaform" action="mailto:email@address.com?subject='From the suggestion box'">

Notice the difference? The 'single quotes' that wrap the subject line string are enclosed by the "double quotes" wrapping the entire mailto: string.

Don't forget to add the method and enctype attributes I mentioned!

If you need further assistance building a proper mail form that submits to a server-side script, please let us know.

3:10 pm on Mar 17, 2009 (gmt 0)

5+ Year Member

Thanks Blang, I hadn't noticed that in my tizzy about the rest of it! I'm so used to just using " after a = :-D

But I would love some help with the server-side script and form, if you wouldn't mind...cheers!

4:16 pm on Mar 17, 2009 (gmt 0)

5+ Year Member

But I would love some help with the server-side script and form, if you wouldn't mind...cheers!

Sure; the forums here are a great place to get help on that. If you need personalized help, you can send me a PM (sticky mail on my profile) and we can open a dialog into getting you setup.
8:22 pm on Mar 17, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Another negative to any "mailto" approach: this will only work if the user has, and uses, an offline client such as Outlook, Eudora, Thunderbird, etc. The browser executes the default mail program on the computer and opens a new email with the to: and subject: populated (you can also populate body.)

But if someone uses an online mail service, such as Yahoo, Gmail, etc., this won't work. It will open the default mail client and most likely confuse the user.

10:56 pm on Mar 17, 2009 (gmt 0)

5+ Year Member

Excellent point. I myself had a hard time when testing the markup on this one! Some users could have the Yahoo! or Google toolbars and thus have their web client set as their default, but overall a CGI script processing the form is best.
9:11 am on Mar 18, 2009 (gmt 0)

5+ Year Member

Oh I didn't realise the mailto: attribute automatically opened up the email anyway. That was my problem then! See, I'm a complete newb at anything other than HTML or CSS, and I'm only self-taught in both of those. Blang, I've sent you a sticky, thanks :-)

Featured Threads

Hot Threads This Week

Hot Threads This Month