Using the ASPEmail Component.
The ASPEmail script is an example of using a script to input form information and then emailing it using ASP and the ASPEmail component.
Dim toAddress, subject
toAddress = "support@easycgi.com"
subject = "Thanks for testing this great Easy CGI Form!"
Here we define two variables that will hold the subject of the email to be sent and the address that the email will be sent to.
if request.form("submit") <> "" Then
Since the code to send the email and output the form is in this script, we must check if the form is being submitted. If it is the email will be sent, if it is not then we will skip past the email code and output the form.
Set Mail = Server.CreateObject("Persits.MailSender")
Sets the mail object to use, which is ASPEmail.
Mail.Host = "mail.easycgi.com"
We set the address of the mail server.
Mail.From = request.form("email")
Takes the email address that was submitted in the form by the user and sends the mail from that address. In order for the mail to be sent properly, this should be a valid address.
Mail.FromName = request.form("email")
Specifys the name of the person the mail will be sent from taken from the form also.
Mail.AddAddress toAddress
Adds the email address that the email will be sent to, taken from the variable that was defined above. You can add multiple recipients by just adding another line like: Mail.AddAddress toAddress2.
Mail.AddReplyTo request.form("email")
This lets you specify the reply to address of the email. In this case we use the same address that the email is being sent from, but they can be different.
Mail.Subject = subject
This sets the subject of the email to the variable that was defined above.
Mail.Body = "Easy CGI ASP Test Form: " & vbcrlf & _
"------------------------" & vbcrlf & vbcrlf & _
"First name: " & request.form("fname") & vbcrlf & vbcrlf & _
"Last name: " & request.form("lname") & vbcrlf & vbcrlf & _
"Email: " & request.form("email") & vbcrlf & vbcrlf & _
"Comments: " & request.form("comments") & vbcrlf
Here we set the body of the email to be sent. It takes the information that was passed in from the form and puts some line breaks in between them.
On Error Resume Next
Tells the script to continue executing if an error occurs.
Mail.Send
The most useful line, this actually sends the email.
The next lines display that the email was sent or an error if it occurred.
Else
This tells the code to output the form if the form was not submitted.
The rest of script is the HTML for displaying the form.
--Here is the full script, the filename should be: aspemail.asp--
<%
'Easy CGI Test Form for sending email via ASPEmail
'Change these values to test the form
'-------------------------------------
Dim toAddress, subject
toAddress = "support@easycgi.com"
subject = "Thanks for testing this great Easy CGI Form!"
'-------------------------------------
'Check to see if the form was submitted
if request.form("submit") <> "" Then
if it was then send the email
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "mail.easycgi.com" ' Specify a valid SMTP server
Mail.From = request.form("email") ' Specify sender's address
Mail.FromName = request.form("email") ' Specify sender's name
Mail.AddAddress toAddress
Mail.AddReplyTo request.form("email")
Mail.Subject = subject
'Add the form fields to the message body
Mail.Body = "Easy CGI ASP Test Form: " & vbcrlf & _
"------------------------" & vbcrlf & vbcrlf & _
"First name: " & request.form("fname") & vbcrlf & vbcrlf & _
"Last name: " & request.form("lname") & vbcrlf & vbcrlf & _
"Email: " & request.form("email") & vbcrlf & vbcrlf & _
"Comments: " & request.form("comments") & vbcrlf
On Error Resume Next
Mail.Send
If Err <> 0 Then
Response.Write "Error encountered: " & Err.Description
Else
Response.Write "Thank you for submitting your information!"
End If
Else
'if the form was not submitted then output the form html
<HTML>
%>
<CENTER><B><FONT SIZE=+2>Easy CGI Test Form for ASPEmail</FONT></U></B></CENTER></P>
<form action="aspemail.asp" method="post">
<TABLE>
<TR>
<TH>First Name:</TH><TH><input type="text" name="fname" align ="right" size=40></TH>
</TR>
<br>
<TR>
<TH>Last Name:</TH><TH><input type="text" name="lname" align ="right" size=40></TH>
</TR>
<br>
<TR>
<TH>Email:</TH><TH><input type="text" name="email" align ="right" size=40></TH>
</TR>
<TR>
<TH>Comments:</TH><TH><TEXTAREA name="comments" rows="8" cols="30" align ="right">
<TR>
</TABLE>
<input type="submit" value="Submit" name="submit">
</form>
</HTML>
<%
End If
%>
--End Script--
More detailed examples of the ASPEmail Component can be found at: http://www.aspemail.com/
<< Back |