Uggle Internet Web Hosting

 


This tutorial will explain how to add a form to your site that emails the results to you. This tutorial uses the JMail component which is installed on all of our servers.

The example form collects three peices of information and sends it to the asp script for processing. We have added an additional validation script in our example to ensure that all fields are completed (using Dreamweaver).

Example form:

Your Name
Your Email Address
Your Enquiry

Copy the html below and paste into your own page:

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>

<form name="form1" method="post" action="contact.asp">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="150" height="45" align="left" valign="bottom"><div align="left">Your Name</div></td>
<td width="278" align="left" valign="bottom"><input name="your name" type="text" id="your name" size="30"></td>
</tr>
<tr>
<td width="150" height="30" align="left"><div align="left">Your Email Address </div></td>
<td align="left"><input name="your email address" type="text" id="your email address" size="30"></td>
</tr>
<tr>
<td width="150" height="146" align="left" valign="top"><div align="left">Your Enquiry </div></td>
<td align="left" valign="top"><textarea name="your enquiry" cols="40" rows="4" id="your enquiry"></textarea>
<br>
<input name="Submit" type="submit" onClick="MM_validateForm('your name','','R','your email address','','RisEmail','your enquiry','','R');return document.MM_returnValue" value="Submit"></td>
</tr>
</table>
</form>

The example script will send the details obtained in the form to a page titled contact.asp.

The ASP page below contains the scripting to send the information via plain text email. Copy the html below and paste to a new web page (paste into notepad and save as contact.asp). Be sure to edit the mail settings before saving.

This file needs to be uploaded to the same directory as the form page.

Edit the page to your requirements.

<html>
<head>
<title>Form submitted</title>
</head>

<body>
<%
Name = Request.Form("your name")
SenderEmail = Request.Form("your email address")
Subject = "You have an enquiry from your website!"
' Below you should enter your own email address
Recipient = "mail@mysite.co.uk"
Body = Request.Form("your enquiry")

Set JMail = Server.CreateObject ("JMail.SMTPMail")

' Below you should enter your own SMTP-server
JMail.ServerAddress = "mail.uggle.co.uk"

JMail.Sender = Senderemail
JMail.Subject = Subject

JMail.AddRecipient Recipient

JMail.Body = Body

JMail.Priority = 3

JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")

JMail.Execute

%>
<p>Thank you <%=name%>,</p>
<p>Your enquiry has been submitted.</p>
<p>We will contact you ASAP. </p>
</body>
</html>


 

To send HTML email use JMail.HTMLBody instead of JMail.Body .

 

Uggle Internet Web Hosting
Status Verified by
Web Hosting Stuff

Powered by HELM the WebHosting Control System