JavaScript - form to send email
Email
Form in Javascript
This was sent to me to try out and it does work. I modified the form
in JavaScript to make it harder for some web bots to identify the actual
address.
To make the form harder to be crawled by web crawlers you should save this
code as an external JS file. Then on your html page call the JS into
your page to be displayed on an onload.
-----------------------------------------
<script language="JavaScript"><!--
function valid(form) {
var field = form.email; // email field
var str = field.value; // email string
var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
// valid
if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
alert("Thank your for your comments."); // this is optional
return true;
}
alert("\"" + str + "\" is an invalid e-mail!"); // this is also optional
field.focus();
field.select();
return false;
}
// -->
</script>
<script language="JavaScript"><!--
document.write('<FORM METHOD="POST"')
document.write('ACTION="mailto:')
document.write('youremailnamehere')
document.write('@')
document.write('yourmailservernamehere')
document.write('.com" ENCTYPE="text/plain"
onSubmit="return valid(this)">')
document.write('Your e-mail address:<BR><INPUT TYPE="text" NAME="email"
SIZE="40">')
document.write('<BR>Your Name:<BR><INPUT TYPE="text" NAME="name"
SIZE="40"><BR>Subject:<BR>')
document.write('<INPUT TYPE="text" NAME="subject"
SIZE="40"><BR>Comments:<BR>')
document.write('<TEXTAREA NAME="comments"
COLS="40" ROWS="5"></TEXTAREA><BR>')
document.write('<INPUT TYPE="submit" VALUE="Send Mail">')
document.write('</FORM>')
// -->
</script>
-----------------------------------------
NOTE: You need to change the email address
to where is is to be sent.
NOTE: You can create more input fields just
make sure you NAME="them"
Working sample form below:
Enjoy!!!
|