Support Centre

Creating a Contact Form

4*4*4*4*4*

Article

Adding a Contact Form to your Windows hosted site

Creating a contact form for your website requires 2 files, the web form in which the end user enters their message/enquiry and the script which processes this information and generates an email to you.

The first step is to create the actual contact form. This can be called anything you like, but for this example we'll call it contact.asp (Note: You can add this code to an existing contact page rather than make a new one should you wish)

<form method="POST" action="sendmail.asp">         
Subject <input type="text" name="Subject"/> <br />         
Body <textarea name="Body" rows="5" cols="20" wrap="physical" >          
</textarea>         
<input type="submit" />         
</form>

Now to create the script that does the hardwork behind the scenes. As you can see we have referenced 'sendmail.asp' in the contact form code - so our mail script needs to be named 'sendmail.asp' in order for this to work. Add the following code to your 'sendmail.asp' file:-

<%         
'Sends an email         
Dim mail         
Set mail = Server.CreateObject("CDO.Message")         
mail.To = "address@yourdomain.com"         
mail.From = "address@yourdomain.com"         
mail.Subject = Request.Form("Subject")         
mail.TextBody = Request.Form("Body")         
mail.Send()         
Response.Write ("Mail Sent! Thank You")         
'Destroy the mail object!         
Set mail = nothing         
%>

(Replace address@yourdomain.com with the email address you would like form submissions to be sent to, and appear from)

All thats left to do now is to upload both files to the same directory within your hosting space.

The above example provides a basic contact form which will deliver an email to your chosen account, from a set address, and will include the subject and body text, as entered by the user. However, you may wish for your form to collect more information, or to redirect to another page on completion. Below I have included a few options to show how you can expand the functionality of your form.

This form and script will also ask for the users name & email address, it will include this information in the email which is generated to you, and redirect the user to a Thank You page called 'thankyou.asp' after submission. (Additional text and alterations have been highlighted in bold)

contact.asp

<form method="POST" action="sendmail.asp">         
Your Name <input type="text" name="YourName"/> <br />       
Email Address <input type="text" name="EmailAddress"/> <br />        
Subject <input type="text" name="Subject"/> <br />         
Body <textarea name="Body" rows="5" cols="20" wrap="physical" >          
</textarea>         
<input type="submit" />         
</form>

sendmail.asp

<%         
'Sends an email         
Dim mail         
YourName = Request.form("YourName")       
Body = Request.form("Body")       
EmailAddress = Request.form("EmailAddress")        
Set mail = Server.CreateObject("CDO.Message")         
mail.To = "address@yourdomain.com"         
mail.From = "address@yourdomain.com"         
mail.Subject = Request.Form("Subject")         
mail.TextBody = YourName + vbcrlf + EmailAddress + vbcrlf + Body         
mail.Send()       
Response.Redirect "http://www.yourdomain.com/thankyou.asp"       
'Destroy the mail object!         
Set mail = nothing         
%>

We would recommend adding a 'captcha' or another form of verification to your contact form in order to increase security.

Scripts are provided as an example, and will not be supported by our Customer Support team

Rate This Article

How useful was this article?

Not useful A little useful Useful Very useful Everything I needed