Knowledge
Base Article
Windows - ASP Form to
Email Tutorial and Example
ASP FormMail
1. In order to
create the Form-to-Email action in your web page, you
need to define the following elements:
Target Email-
something@yourdomain.com
(Note: This email needs to be on the same domain as the
form - ie. www.yourdomain.com)
Redirect Page - Upon successful submission of the
form, this is the page which the user will be redirected
to after the form has been successfully submitted. This
page can be any page within your site, or to any valid
address on the Internet.
Form Fields - These are the fields which the user
fills, which are sent to via email to the target email.
These fields may be single line text boxes, multiple
line text boxes, radio buttons, etc...
2. Create the form within your web page:
|
<FORM
id="form1" name="form1" action="feedback.asp"
method="post" dir="ltr" >
Name:<input size="40" name="name"><br>
Account Username:<input size="40"
name="username"><br>
email:<input size="40" name="email"><br>
Feedback Message
<TEXTAREA rows="5" cols="45" ID="comments"
NAME="feedback" class="heading2"></TEXTAREA><br>
<input type="submit" value="Send" name="B1">
</form> |
3. Create a file called "formscript.asp", with the
following contents:
|
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft
FrontPage 6.0">
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-8">
<TITLE>domain contact form</TITLE>
</HEAD>
<%'----- begin sending ----
function YesNo(cb)
YesNo="No"
if cb="on" then YesNo="Yes"
end function
'------------
dim sHost
dim sUserName
dim sPassword
sHost = "mail.domain.com" ' valid smpt server
sUserName = "postmaster@domain.com"
' valid email
sPassword = "post7"
Set Mail =
Server.CreateObject("Persits.MailSender")
' enter valid SMTP host
Mail.Host = sHost
Mail.Username = sUserName
Mail.Password = sPassword
Mail.From = "postmaster@domain.com" ' From
address
Mail.AddAddress "form@domain.com"
' recipient address - must be on same domain as
form
' message subject
Mail.Subject = "domain contact form"
' message body
dim cadena
cadena="From" & "<br><br>"
cadena=cadena &
Request.ServerVariables("REMOTE_ADDR") & "<br>"
cadena=cadena & cstr(now) & "<br><br>"
' The following lines were copied from:
'
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=64
For ix = 1 to Request.Form.Count
fieldName = Request.Form.Key(ix)
fieldValue = Request.Form.Item(ix)
cadena=cadena & fieldName & ": "
cadena=cadena & fieldValue & "<br>"
Next
body="<html><body><META
http-equiv='Content-Type' content='text/html;
charset=iso-8859-8'><font color=navy>" & _
"<span dir=rtl align=right>"
body=body & cadena
body=body & "</span></font></body></html>"
Mail.IsHTML = True
Mail.CharSet="iso-8859-8"
Mail.Body = body
strErr = ""
bSuccess = False
On Error Resume Next ' catch errors
Mail.Send ' send message
If Err <> 0 Then ' error occurred
strErr = Err.Description
Response.Write "An error occurred when trying to
send the email"
else
bSuccess = True
Response.Redirect("http://www.domain.com/thanks.html")
End If
set mail=nothing
%>
</BODY>
</HTML> |
4. Good luck.
If you have any questions, please contact us
here.