One of the most common ways to send form data is with the AspMail component. In this script, we will use AspMail to send data from a basic contact form including text and textarea boxes.
The first thing you need to do is create a /FormPage.asp page with the code below:
<form name="YourFormName" method="Post" action="confirmation.asp">
Email: <input type="text" name="Email" size="50"><br>
First Name: <input type="text" name="FirstName" size="50"><br>
Last Name: <input type="text" name="LastName" size="50"><br>
Subject: <input type="text" name="Subject" size="50"><br>
Comments: <textarea name="Comments"></textarea><br>
<input type="submit" name="Submit" value="Submit Form">
</form>
Next, we create a /Confirmation.asp page with our AspMail code as seen below:
<%
DIM strEmail, strFirstName, strLastName, strSubject, strComments
strEmail = request.form("Email")
strFirstName = request.form("FirstName")
strLastName = request.form("LastName")
strSubject = request.form("Subject")
strComments = request.form("Comments")
DIM Mailer, strMsgHeader, qryItem, strMsgInfo
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = strFirstName
Mailer.FromAddress= strEmail
Mailer.ReplyTo = strEmail
Mailer.RemoteHost = "YourDomain.com"
Mailer.AddRecipient "YourNameHere", "YourEmail@YourDomain.com"
Mailer.Subject = "Website Contact Form"
strMsgHeader = "This email was sent from the YourDomain.com website" & vbCrLf
Mailer.BodyText = strMsgHeader & vbCrLf & "Email: " & Request.Form("Email") & _
vbCrLf & "First Name: " & Request.Form("FirstName") & _
vbCrLf & "Last Name: " & Request.Form("LastName") & _
vbCrLf & "Subject: " & Request.Form("Subject") & _
vbCrLf & "Comments: " & Request.Form("Comments")
IF Mailer.SendMail THEN
Response.Write strFirstName & ",<br>"
Response.Write "Your message has been sent and will be reviewed shortly."
ELSE
Response.Write "An error has occurred: " & Mailer.Response
END IF
%>
Now you have a form that sends data to an email address and displays a customized message for the message sender. The default format for AspMail is to send plain text messages. If you want to send HTML messages with AspMail, you can simply include this extra line of code before the Mailer.BodyText line.
Mailer.ContentType = "text/html"
Enjoy!