Using the ASPMail script is a very straightforward process. All you need do is specify a page on your web site as the "action" page for your form, and then include the ASPMail script on that page.
Each form on your website will consist of 2 pages: A "form" page which actually holds your form, and an "action" page which processes your form when someone clicks on the "submit" button. For purposes of this discussion, we will refer to these pages as "form.html" and "aspmailform.asp". *
*Note: Your action page must have a .asp extension, even though it is an ordinary HTML file.
Once you have constructed your form using regular HTML make sure that your <form> tag specifies the "post" method, and that the action statement points to your "action" page. Example:
<form action="aspmailform.asp" method="post">
Then, on your action page (aspmailform.asp) you will need to add a block of code similar to the one below. The Mailer.RemoteHost line will be "mail.yourdomain.xyz" (where .xyz is your domain extension such as .com). Please note that your domain must be pointing to our service and you must be using our DNS servers for this to work properly.
<%
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = "WebsiteOrAnything"
Mailer.FromAddress= "name@yourdomain.com"
Mailer.RemoteHost = "mail.yourdomain.com"
Mailer.AddRecipient "Name", "name@yourdomain.com"
Mailer.Subject = "Form Submission"
strMsgHeader = "Form information follows" & vbCrLf
for each qryItem in Request.Form
strMsgInfo = strMsgInfo & qryItem & " - " & request.Form(qryItem) & vbCrLf
next
strMsgFooter = vbCrLf & "End of form information"
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter
if Mailer.SendMail then
Response.Write "Form information submitted..."
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if
%>
Order your ASPMail Fields
To return form contents in the original form order your code might be ...
strMsgHeader = "Form Information Follows: " & vbCrLf
for i = 1 to Request.Form.Count
strMsgInfo = strMsgInfo & Request.Form.Key(i) & " - " & Request.Form.Item(i) & vbCrLf
next
strMsgFooter = vbCrLf & "End of form information"
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter
Note: This code only works for forms containing 128 or fewer field items.
The pertinent lines of this code are explained below:
Set Mailer = Server.CreateObject("SMTPsvg.Mailer") |
Do not alter this line |
| Mailer.FromName = "Website" | Optional, this text will appear in the "from" field on the E-mail message that is sent. You may use an E-mail address here. |
| Mailer.FromAddress = "webmaster@yourdomain.com" | Required: a valid E-mail address from your domain. |
| Mailer.RemoteHost = "mail.yourdomain.com" | Required: Enter the address of the mail server for your domain. |
| Mailer.AddRecipient "Domain Webmaster", "webmaster@yourdomain.com" | Required: and in two parts. The first part ("Domain Webmaster") can be any name or an E-mail address. The second part ("webmaster@yourdomain.com") must be a valid E-mail address. |
| Mailer.Subject = "Form Submission" | This will be the title of your E-mail message. |
| Do not alter any other line of the code. | |