First thing you will need to do is specify the scripting language, content type and endcoding type in a page element. Language will be visual Basic, content Type will be text/html and ecoding will be iso-8859-1
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
Next you will want to specify the doctype, this will tell the browser exactly what type of HTML you are using in the page. We'll be using the following DTD HTML doc type.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Now we need to import the System.Web.Mail asp.net namespace for use with our basic contact form
<%@ Import Namespace="System.Web.Mail" %>
Now that the page basics are setup we need to write some script that will handle the information browsers will provide when visiting your page. First you need to write the server side script call. Then include a runat="server" verable which will tell the server to run it locally on the server side so the browser cannot view the information. This is done to prevent souce view bots from gaining email address information in your contact form.
<script runat="server">
Server side code
Sub btnSubmit_Click(sender as object, e as EventArgs)
Dim objEMail As New MailMessage()
objEMail.To = "enter the email address you want to send to here"
objEmail.From = txtFrom.Text
objEmail.Subject = txtSubject.Text
objEmail.Body = "Name: " &txtName.Text & vbcrlf & "Email: " &txtFrom.Text & vbcrlf & "Comments: " &txtBody.Text
objEmail.Priority = MailPriority.High
SmtpMail.SmtpServer = "Enter your mail server domain here"
try
SmtpMail.Send(objEMail)
'Success Options:
'Response.Write("success")
'Response.Redirect("/success page/")
catch exc as Exception
Response.Write("Send failure: " + exc.ToString())
End Try
End Sub
then you need to end the runat=server code
</script>
add standard HTML elements
<html>
<head>
<title>Contact Form by Shawn Hyde</title>
</head>
<body>
Now the form, form fields and content
<form id="ContactMain" runat="server">
<table width="600" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td height="24" colspan="2" align="right" valign="top"> </td>
</tr>
<tr>
<td width="28%" align="right" valign="top">Name :</td>
<td width="72%" height="24" valign="top">
<asp:TextBox runat="server" Width="200px" ID="txtName"></asp:TextBox> </td>
</tr>
<tr>
<td align="right">Email :</td>
<td height="24" valign="top"><asp:TextBox runat="server" Width="200px" ID="txtFrom" ></asp:TextBox> </td>
</tr>
<tr>
<td align="right">Subject : </td>
<td height="24" valign="top"><asp:TextBox runat="server" Width="200px" ID="txtSubject" ></asp:TextBox></td>
</tr>
<tr>
<td align="right" valign="top">Comments : <br>
<br></td>
<td valign="top"><asp:TextBox runat="server" TextMode="MultiLine" Height="80px" Width="250px" ID="txtBody"></asp:TextBox> </td>
</tr>
<tr>
<td colspan="2" align="center">Proxy(<% = Request.ServerVariables("HTTP_X_FORWARDED_FOR")%>
) IP(
<% = Request.ServerVariables("REMOTE_ADDR")%>
) Validation & Time Stamp :
<% = Now %>
</td>
</tr>
<tr>
<td colspan="2" valign="top" height="30">
<p align="center">
<asp:Button Runat="server" ID="btnSubmit" OnClick="btnSubmit_Click" Text="Submit"></asp:Button>
<input type = "reset" value = "Clear" runat = "server">
</td>
</tr>
</table>
<br>
</form>
Finally closing of page HTML elements
</body>
</html>
Posted
06-12-2009 1:21 PM
by
Shawn Hyde