View Full Version : A Javascript for sending emails by using a form on a webpage?

12-20-2005, 01:47 AM
Sorry if it's a complicated question. I need help with this so I turned here; I'm sorry if I'm doing something wrong.

What I'm trying to say is that, is there a script that makes a form box on a webpage with default words inside of it, and once the user types the things out, a link is pressed and what was in the form is sent as an email?

It's sort of like an application kind of thing, where the default words are questions in my case.

I've tried googling but no success.

Thanks in advance,
Moogle ^_^

12-20-2005, 06:44 AM
You can set the values of the boxes with html but to actually get the information to be sent you will need a server side language, javascript is clientside and cannot do this.

12-20-2005, 12:24 PM

If you are unable or unwilling to use server side language, the following will work in IE only.

<script type="text/javascript">

function sendMail(isForm){

isBody = "";
recipient = "me@someDomain.com";
isSubject = "Form Data";
isBody = "Name: " + isForm.personal.value +"%0D%0A";
isBody += "Address: " + isForm.address.value +"%0D%0A";
isBody += "City: " + isForm.city.value +"%0D%0A";
isBody += "State: " + isForm.state.value +"%0D%0A";
isBody += "Zip: " + isForm.zip.value;
document.forms.Send.action = "mailto:"+recipient+"?subject="+isSubject+"&body="+isBody+"&nbsp";

<form name='Form1'>
Name <input type='text' name='personal' value="John Doe" size=25><br>
Address <input type='text' name='address' value="123 Main Street" size=30><br>
City <input type='text' name='city' value="Springfield" size=15> State <input type='text' name='state' value="OH" size=2><br>
Zip Code <input type='text' name='zip' value="12345" size=4><br>
<form name='Send' action=''>
<input type="submit" value="Send by Email" onclick="sendMail(document.Form1)">

12-24-2005, 12:17 AM
Thank you very much ^_^ That's just what I needed.

Happy holidays :)

12-25-2005, 10:27 PM
That code will only work if there is a separate email program available on the computer (which rules out internet cafes and may other users). Also it doesn't work on modern browsers. Also it gives your email address to the spammers. 99% of the emails resulting from the code will be spam.

Use a server side solution. If you don't have access to put a script on your own site then use a third party one from somewhwere like Bravenet.