Form To E-mail Sample Using ASPMail
This is a short
example of how to send data entered in a form to an email address.
In this example, a visitor submits a name, email address, and brief
message on a web form. Two emails are then created, one to the web
site owner and one to the visitor. The visitor is then redirected
to a thank you page.
Step 1 - The Form
Page (Form.htm):
This is the html form
that is going to collect the information that you want to email.
Step 2 – The Email
Processing Page (Aspmail.asp):
You need to create a
page named "aspmail.asp" to process the information from the form
page. Place this in the root of your directory.
**Please read the
contents of this script carefully and enter your domain information
where necessary.
<body>
<%
' This creates the smtp mail server object.
Set Mailer= Server.CreateObject("SMTPsvg.Mailer")
' This is the mail server that will send your email.
Mailer.RemoteHost= "mail.yourdomain.com"
' When the email is generated, this is who the mail is from, it
is from the email field in Form.htm.
Mailer.FromAddress = Request.Form("txtEmail")
' This is the
name of the person the email appears to come from, it is from the
Name field in Form.htm.
Mailer.FromName = Request.Form("txtName")
' This is
who the first email will be sent to, please enter your domain email
address here.
Mailer.Recipient= "a_valid_account@yourdomain.com"
' This is the subject of the message.
Mailer.Subject = "enter
your subject here"
'this set the mail priority to High. 2 is
Normal, 3 is
Low
Mailer.Priority = 1
' Mailer.BodyText is the body of the message. Here standard text
is combined
' with form variables to make it easier to read. This is the email
that is sent to the
' website owner which contain the form information.
Mailer.BodyText= Request.Form("txtName") & " has submitted the
following message" & vbCrLf & vbCrLf & _
"Name: " & vbCrLf & _
Request.Form("txtName") & vbCrLf & vbCrLf & _
"Email: " & vbCrLf & _
Request.Form("txtEmail") & vbCrLf & vbCrLf & _
"Message: " & vbCrLf & _
Request.Form("txtMessage")
' This code handles what will happen when the form is ready to
process.
' The first part is when the form is ready to send.
IF Mailer.SendMail then
Set Mailer = Nothing
ELSE
' If there was an error in sending an email, this code will
output to the screen
Set Mailer = Nothing
Response.Write "Your message was not sent."
Response.Write Mailer.Response
END IF
' This code
opens a new mailer object and sends an email to the respective
visitor.
Set Mailer=
Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost= "mail.yourdomain.com"
Mailer.FromAddress = "a_valid_account@yourdomain.com"
Mailer.FromName = "your
name"
Mailer.Recipient= Request.Form("txtEmail")
Mailer.Subject = "enter
subject here"
Mailer.BodyText= Request.Form("txtName") & "," & vbCrLf & vbCrLf & _
"enter
your message here."
IF
Mailer.SendMail then
Set Mailer = Nothing
' When the form
is sent, the user is redirected to the page below.
' This should be set to your own personal thank you page
Response.Redirect "http://www.yourdomain.com/thankyou.asp"
ELSE
' If there was an error in sending an email, this code will
output to the screen
Set Mailer = Nothing
Response.Write "Your message was not sent."
Response.Write Mailer.Response
END IF
%>
</body>
Step 3 - Your Thank
You Page:
You will need to
create a Thank You page and place this in the root directory of your
domain.
-
Create a file
named thankyou.asp or thankyou.htm. This will be your own
personal thank you page please enter what you wish
-
Upload this file
to your root directory.