|
|
ASP Scripts
EMAIL THIS PAGE
Another simple and very valuable tool to add to your website
is the Email This Page tool. In this example, you can allow
users to send the URL of any page within your website to any
email address they choose. For our purposes, we will use ASPMail
for sending mail
First, place this link on your home page:
<HTML><HEAD>
<TITLE>ASP Web Pro</TITLE>
</HEAD>
<BODY>
<A HREF="../emailthispage.asp">Email This Page</A>
</BODY>
</HTML>
|
Next, create a page in your root directory called emailthispage.asp
and paste the following code:
<HTML><HEAD>
<TITLE>ASP Web Pro</TITLE>
</HEAD>
<BODY>
<FORM action="emailthispageconfirm.asp"
method="post" name="Emailthispage">
<%
DIM strURL
strURL = Request.ServerVariables("HTTP_Referer")
IF strURL = "" THEN
Response.Write "Sorry, your browser does not
support this function."
END IF
%>
<p><b>Page Link:</b> <%= strURL
%></p>
<TABLE width="100%" border="0">
<TR><TD width="25%"><DIV
align="right">Your Email:</DIV></TD>
<TD width="75%"><input type="text"
name="YourEmail" size="40"></TD></TR>
<TR><TD width="25%"><DIV
align="right">Your First Name:</DIV></TD>
<TD width="75%"><input type="text"
name="YourName" size="40"></TD></TR>
<TR><TD width="25%"><DIV
align="right">Recipient's Email:</DIV></TD>
<TD width="75%"><input type="text"
name="RecipEmail" size="40"></TD></TR>
<TR><TD width="25%"><DIV
align="right">Recipient's First Name:</DIV></TD>
<TD width="75%"><input type="text"
name="RecipName" size="40"></TD></TR>
</TABLE>
<TABLE width="100%" border="0">
<TR><TD>Comments:</TD></TR>
<TR><TD><TEXTAREA name="Comments"
cols="50"></TEXTAREA></TD></TR>
</TABLE>
<input type="hidden" name="URL"
value="<%= strURL %>">
<input type="submit" value="Submit">
</FORM>
</BODY>
</HTML>
|
Last, create a confirmation page called emailthispageconfirm.asp,
paste the following code, and customize it with your own domain
name and mailing info:
<HTML><HEAD>
<TITLE>ASP Web Pro</TITLE>
</HEAD>
<BODY>
<%
DIM Mailer, strEmail, strMsgHeader, qryItem, strMsgInfo
DIM strYourEmail, strYourName, strRecipEmail, strRecipName,
strComments, strURL, Mail
strYourEmail = Request.Form("YourEmail")
strYourName = Request.Form("YourName")
strRecipEmail = Request.Form("RecipEmail")
strRecipName = Request.Form("RecipName")
strComments = Request.Form("Comments")
strURL = Request.Form("URL")
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromAddress = strYourEmail
Mailer.ReplyTo = strYourEmail
Mailer.RemoteHost = "YOUR_DOMAIN_NAME.COM"
Mailer.AddRecipient strRecipName,
strRecipEmail
Mailer.Subject = "Look at this page from the
YOUR_WEBSITE_NAME_HERE website"
strMsgHeader = "This mail message was sent from
the YOUR_DOMAIN_NAME_HERE website" & vbCrLf
& vbCrLf
Mailer.BodyText = strMsgHeader & vbCrLf &
strRecipName & "," & vbCrLf &
vbCrLf & strYourName & " wants you to
take a look at this page at YOUR_WEBSITE_NAME_HERE:"
& vbCrLf & "Page Link: " & strURL
& vbCrLf & vbCrLf & strComments
IF Mailer.SendMail THEN
%>
<%
strYourName = request.form("YourName")
Response.Write strYourName
%>
,</p>
<p>Thank you for sharing this page with
<%
strRecipName = request.form("RecipName")
Response.Write strRecipName
%>
. Your message has been sent successfully and will
be received by
<%
strRecipName = request.form("RecipName")
Response.Write strRecipName
%>
shortly.</p>
<%
ELSE
Response.Write "Sorry, there was an error and
your email could not be sent at this time."
END IF
%>
</BODY>
</HTML>
|
That's all there is to it. The confirmation page is even
customized so that it displays the sender's and recipient's
names. Now, anytime one of your website users sees something
interesting, they can email that page link to any email address
they want. In essence, it helps drive more traffic to your
website!
< Back to
ASP Scripts
|