ASPMail | ASPMail Email Component Script by ASP Web Pro
  ASPMail | ASMail Email Component Script

ASP Scripts

ASPMail

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 text box and a textarea box.

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">
<table>
<tr><td>Email: </td>
<td><input type="text" name="Email" size="50"></td></tr>
<tr><td>First Name: </td>
<td><input type="text" name="FirstName" size="50"></td></tr>
<tr><td>Last Name: </td>
<td><input type="text" name="LastName" size="50"></td></tr>
<tr><td>Subject: </td>
<td><input type="text" name="Subject" size="50"></td></tr>
<tr><td>Comments: </td>
<td><textarea name="Comments"></textarea></td>
</table>
<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, Mailer
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 = "ASP Web Pro Online"
Mailer.FromAddress= "root@aspwebpro.com"
Mailer.ReplyTo = strEmail
Mailer.RemoteHost = "aspwebpro.com"
Mailer.AddRecipient "ASP Web Pro", "general@aspwebpro.com"
Mailer.Subject = "ASP Web Pro Website: Online Form"
strMsgHeader = "This mail message was sent from the www.aspwebpro.com Online Form" & vbCrLf & 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 successfully sent."
ELSE
Response.Write "The following error occurred while sending your message: " & Mailer.Response
END IF
%>

Now you have a complete form that sends data to an email address and displays a customized message for your user. 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!

< Back to ASP Scripts


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
16 March 2010