Mail A Link

Enabling people to mail the link of the current page is an incredibly useful feature to incorporate into your site. People can easily share items viewed with others and mail items without the need for an internet capable email account and bring users back to your site for a second view.

There are many ways that this can be accomplished. The following is probably one of the easiest to incorporate. On each page you will need to provide a link or input button that will link to the mail application. When clicked, the referring page url will always be available to display as request.servervariables("http_referer"). However, mailing a link without knowing much about its contents does not do much. So, by utilizing some simple JavaScript the title of the page can easily be passed and incorporated into the email message. This example demonstrates the use of CDONTS for mailing your info. You may also want to include a note on you page detailing that mail addresses are not collected to let people feel secure that their info is not being gathered in your application. 

mailalink.htm
<html>
 <title>Mail A Link Example</title>
 <body bgcolor="#FFFFFF">
 <!-- Either of the following should be placed on the page(s)
 you like to have the mail a link featured on -->
 <form action="mailalink.asp" method="post">
 Mail A Link Form Example<br>
 <script language=JavaScript>
 var title = "<input type='hidden' name='title' value='" + document.title + "'>"
 document.write (title)
 </script>
 <input type="submit" value="Mail This Link">
 </form>
 
 
Mail A Link Hyperlink Example<br>
 <script language=JavaScript>
 var title = "<a href='mailalink.asp?title=" + document.title + "'>Mail This Link</a>"
 document.write (title)
 </script>
 
</body>
</html>
mailalink.asp
<html>
 <body bgcolor="#FFFFFF">
 <title>Mail-A-Link</title>
 <% ' Grab the title and referring page
 title=trim(request.querystring("title"))
 referer=request.servervariables("http_referer")
 if title = "" then 
 title=trim(request.form("title"))
 end if
 u_submitted=trim(request.form("u_submitted"))
 ' u_submitted checks to see if the form with an email address was submitted
 if referer = "" then
 ' If there is no referring page display an appropriate message
 response.write "You have reached the Mail-A-Link page, but we were unable to recognize the previous page"
 response.end
 end if ' End check for referer
 ' If the form with the email address has been submitted send the mail
 if u_submitted <> "Yes" then
 %>
 <form action="<%= request.servervariables("script_name") %>" method="post">
 <b>Subject:</b> <%= title %>
 <br>
 <b>Link:</b> <%= referer %>
 <p>
 Enter the email address of the recipient<br>
 <input type="text" name="u_email">
 <input type="hidden" name="title" value="<%= title %>">
 <input type="hidden" name="referer" value="<%= referer %>">
 <input type="hidden" name="u_submitted" value="Yes">
 <input type="submit" value="Sumbit">
 
<% else
 referer=request.form("referer") 
 body = "The following link was sent to you by a user of YourServer.com" 
 body = body & "Subject:" & title 
 body = body & "Link:" & referer
 
' This is the beginning of the email creation and execution
 ' Remove the comments before each statement that begins with Set or sm
 ' to actually send the mail message
 
' Create a new mail object on the server
 set sm = server.CreateObject("CDONTS.Newmail") 
 
' Declare what address is sending the message
 sm.from = "requested_link@yourserver.com" 
 
' Write the users subject to the subject of the email
 sm.Subject = "Requested Link:" & title
 
' Declare what address the message is being sent to
 ' The Addressee is set to the inputted value
 sm.to = u_email
 
' Write the users message to the body of the email
 sm.body = u_body 
 
' Send the message
 sm.Send 
 
' Clean up the server object
 set sm = nothing 
 %>
 Your mail has been sent
 <% end if 'end check for submission with an email address %>
 </body>
 </html>


javascript asp mail a link cdonts send a link tell a friend


Back To Top
© 1998 - 2017 psacake.com | My3C's

Version 7.2 | Advertise on this site