Book Section
-----
TY JavaScript 3rd Ed.
Teach Yourself JS 1.5
Teach Yourself DHTML
Teach Yourself JS 1.3
LLWW: JavaScript

General Section
-----
Discussion Forum
Articles / Tips
JavaScript Links
About the Author
Privacy Policy
Contact Me



Other Sites
-----
Website Workshop
JavaScript Weblog

JavaScript Workshop Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Hints: Sending Form Results by Email

 
Post new topic   Reply to topic    JSWorkshop Forum Index -> Articles
View previous topic :: View next topic  
Author Message
mgm
Site Admin
Site Admin


Joined: 13 Jul 2002
Posts: 304
Location: Salt Lake City, UT

PostPosted: Mon Jul 22, 2002 7:37 am    Post subject: Hints: Sending Form Results by Email Reply with quote

One question I am frequently asked is how to send form results by email in JavaScript. This is not an easy question, especially since the scripts for this purpose in the first two editions of my book were missing some key attributes.

The Code

The following is the best possible code, as far as I'm aware, for sending a form by email. But it still isn't very good - see below.

Code:
<html>
<head>
<title>Form Example</title>
</head>
<body>
<h1>Form Example</h1>
Enter the following information. When you press
the Submit button, the data you entered will be
sent by email.
<form name="form1"
  action="mailto:[email protected]"
  enctype="text/plain" method="POST">
<p><b>Name:</b>
<input TYPE="TEXT" LENGTH="20" NAME="yourname">
</p>
<p><b>Address:</b>
<input TYPE="TEXT" LENGTH="30" NAME="address">
</p>
<p><b>Phone: </b>
<input TYPE="TEXT" LENGTH="15" NAME="phone">
</p>
<p><input TYPE="SUBMIT" VALUE="Submit"></p>
</form>
</body>
</html>

If your form doesn't work, follow these steps:
1. Make sure you have specified the correct email address in the action attribute.
2. Make sure you included the enctype and method attributes as in the example above.
3. Throw it out, because even this "best possible" method only works for about half of the users out there.

The Problem

The trouble with using this method to send form results is that it is highly dependent on the browser in use, and on the email client in use. Between these, you're likely to lose about half of your business.

The Solution

It's simple: Don't use JavaScript and HTML to do a Web server's job. Use a server-side script in Perl, PHP, or another language to send the mail and it will work 100% of the time. You don't even have to write one - many are available for free.

One of the most popular scripts is formmail.pl, written in Perl. However, some versions of formmail have major security holes and have been exploited by spammers. Use only the following fixed versions from their official source:
formmail.pl
NMS formmail (improved version)

For PHP, you can write your own form-to-email program easily or use one of the many available for free:
PHP scripts at resourceindex.com

You can even use many remotely-hosted services to send your form results without any code on your own server. There is a list of these services here:
Form processing at resourceindex.com

Conclusion
As one of the most commonly-needed features, it's a shame this particular aspect of HTML forms hasn't been standardized or well supported by browser makers. But even if current browsers improve, your best bet for a reliable email gateway is to use a server-side approach.

Good luck!
_________________
Michael Moncur
Owner and Moderator, The JavaScript Workshop
Read the guidelines before posting: http://jsworkshop.com/posting.html
Back to top
View user's profile Send private message Visit poster's website
Paul Dawson
New member
New member


Joined: 05 Aug 2002
Posts: 3

PostPosted: Tue Aug 06, 2002 1:16 am    Post subject: Reply with quote

hi there

i can get it to send the results to one email address but i need to send it to an email address that has been entered into the form as well the designated email address....can u help????

cheers

Paul
Back to top
View user's profile Send private message
mgm
Site Admin
Site Admin


Joined: 13 Jul 2002
Posts: 304
Location: Salt Lake City, UT

PostPosted: Tue Aug 06, 2002 5:01 am    Post subject: Reply with quote

I could be wrong, but I don't believe there's any way to do that using JavaScript. It can be done server-side, though.
_________________
Michael Moncur
Owner and Moderator, The JavaScript Workshop
Read the guidelines before posting: http://jsworkshop.com/posting.html
Back to top
View user's profile Send private message Visit poster's website
Paul Dawson
New member
New member


Joined: 05 Aug 2002
Posts: 3

PostPosted: Tue Aug 06, 2002 5:13 am    Post subject: Reply with quote

Oh Well...... thanks anyway

Paul
Back to top
View user's profile Send private message
sohnee
Senior Member
Senior Member


Joined: 17 Jul 2002
Posts: 2054
Location: UK

PostPosted: Fri Sep 13, 2002 7:40 am    Post subject: Reply with quote

This was a long time ago - but in case someone uses this for reference...

An easy solution to the problem of needing it sent to multiple e-mail addresses would be to use whatever equivalent your e-mail client has of MS 'Inbox Assistant'.

You can set up a rule to say if you receive a message with the relevant title it autoforwards to the other addresses.
Back to top
View user's profile Send private message Visit poster's website
zachariah
Member
Member


Joined: 07 Sep 2002
Posts: 100
Location: Earth

PostPosted: Wed Sep 25, 2002 7:02 pm    Post subject: Use a PERL script Reply with quote

The best way is to read the documentation in NMS formmail, and do what it says. It tells you how to do exactly what you are asking for. It is really straight forward with only a few variables to set. Plus, it doensn't depend on your client running javascript.

Download it from here (the NMS Matt's Scripts homepage):
http://nms-cgi.sourceforge.net/

Paul Dawson wrote:
... I need to send it to an email address that has been entered into the form as well the designated email address...
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Fri Feb 21, 2003 9:06 am    Post subject: Reply with quote

There are two better ways of doing this, one is to use FormMail which may be supported by your service provider. If so go to the FormMail site and download the instructions on how to use the Perl program.

http://www.scriptarchive.com/formmail.html
or:
http://formmail.to/formmail.to/
http://formmail.to/formmail.to/formhelp.htm

looks like another free service

Both have the documentation.

Another is a free service that will post your form info to a designated address (or two or three) and put up a page of your choice. It is: http://www.response-o-matic.com/

So, if your server does not allow posting via FormMail you can use a line like this:
Code:

<FORM name="Events" action='http://www.response-o-matic.com/cgi-bin/rom.pl' method='post'>

You'll have to go to the site & print out the instructions on how to use their program, there are some required fields.

Last, if your service provider supports PHP it is really simple to make a PHP script to parse the received input & send it on to you. DO NOT PUT or USE the email address in your form, replace it with one in your PHP program this will foil spammers and can be made to ditch any form submitted with multiple adresses.

Hope that helps.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
zachariah
Member
Member


Joined: 07 Sep 2002
Posts: 100
Location: Earth

PostPosted: Tue Feb 25, 2003 9:09 pm    Post subject: FormMail Reply with quote

Phil,

Here's Matt's own words why to use the NMS Matt's Scripts version of FormMail rather than his own (summary: better security and better programming style)
http://www.scriptarchive.com/nms.html

It is the script I mentioned in my previous post.

Zachariah
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Thu Feb 27, 2003 2:05 pm    Post subject: Reply with quote

Zachariah,

I was not suggesting that someone download these Perl scripts but rather they check with their server folks to find out if FormMail was supported. If so, go to the sites I provided in order to learn how to use it.

The other site I believe is a free form mailer that you simply set your form to use and it sends the posted form data as a message back to you.

As your link shows, these kinds of programs have, in the past, had security problems and may have them again in the future. If so, it may well turn out that no one will offer such a free service, let's hope that doesn't happen.

One such free service is located at the URL I provided: http://www.response-o-matic.com/

Now, armed with these I guess someone can either download and use a Perl mailer script like FormMail or a free form to emailing service if they are unable to use Perl or some other server-side language on their site.

I maintain two such sites that do not allow any user server-side scripts so a free emailer service comes in handy at times.

Thanks again for your good link, I didn't know formmail was developed by a former high school student!

To do that kind of thing in PHP is unbelievably easy, the problem is security.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
zachariah
Member
Member


Joined: 07 Sep 2002
Posts: 100
Location: Earth

PostPosted: Tue Mar 04, 2003 11:17 am    Post subject: Reply with quote

Phil,

Thanks for the clarification -- I had misunderstood you.

Zachariah
Back to top
View user's profile Send private message
matt1024
New member
New member


Joined: 20 Jul 2004
Posts: 2

PostPosted: Tue Jul 20, 2004 10:32 am    Post subject: Javascript questionnaire Reply with quote

My friend created this questionnaire for me, but we now need to be able to send the results to an email address.

After reading the article with regards to this I understand we need to use perl or php.

Not being a programmer - just a graphical web creater I am completely lost on the subject, is this an easy thing to do? does the questionnaire have to be rewritten or can the results get sent to a perl script with a button.



thanks

matt


Last edited by matt1024 on Wed Feb 09, 2005 9:50 am; edited 1 time in total
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Wed Aug 04, 2004 9:50 am    Post subject: Reply with quote

This is not the forum to send a question, this is an article with futher clarification.

You need to post this question in one of the forum question areas, we have:
JavaScript
DHTML and CSS
HTML and Web Design
Server-Side Languages

Contact me directly using the link below to my website, perhaps we can exchange services. I need some graphical design help and I have written the perl scripts to send e-mail as I think you want. My website has a send me e-mail button to fill in a form and post the e-mail to me. This one uses a PHP script I wrote.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
Corison
New member
New member


Joined: 29 Aug 2011
Posts: 1
Location: usa

PostPosted: Mon Aug 29, 2011 3:03 am    Post subject: Reply with quote

can we get radio buttons information through an html form template... your informations dont cover this issue?

May be a silly one and would be cool if we can.
Back to top
View user's profile Send private message
paulsaxby82
New member
New member


Joined: 03 Nov 2011
Posts: 1
Location: New york

PostPosted: Tue Nov 08, 2011 3:30 am    Post subject: Reply with quote

Yours information scripts is correct but I donít thing that on server-side you can send emails in JavaScript. Please given me detail script that help me.
_________________
submit articles
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Tue Nov 08, 2011 4:05 am    Post subject: Reply with quote

Corison wrote:
can we get radio buttons information through an html form template... your informations dont cover this issue?

May be a silly one and would be cool if we can.


Yes, of course you can, but ask this question in the JavaScript area, not here.

Or, just go to my website listed below, click on the top-left grid link to "File" in Read: File / Text

once there type in the "Enter Search: " text box the word, "radio" then click the [submit] button and you'll see hi-lighted all files I have that demonstrate the use of radiobuttons as inputs.

A good one to try out & look at the code is help46.htm so go back to the home page of my site & type: help/help46 in the URL: input box & click the green [Go to] button.

You can run the program to see what it does and you can then do a righ-click on the page to view the code. "View Source"

NOTE: That if you get an answer correct the Test Results page will NOT show that question. It only shows the ones you got wrong.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    JSWorkshop Forum Index -> Articles All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
(c) 1997-2002 Starling Technologies and Michael Moncur. Portions (c) Sams Publishing.