Tell a friend using ASP


Suppose your website contains a feature called news where in which you will be updating the website every day with 5-6 articles. In this case if a person likes your article and he wants to recommend that article to his friend he can just click on that button instead of copying the URL and pasting it in his yahoo or hotmail. This is a way to improve traffic to your website.

For example you have a button or link saying that tell a friend then at the end of link you have to provide like this 



<a href="mail.asp?URL=http://www.mywebsite.com">Tell a Friend</a>
So once he clicks on that hyperlink the URL is carried to mail.asp and let us see what mail.asp will do for us.
Open your favourite editor and type this code and name it as mail.asp 
<html>
<head>
<title>Tell a Friend</title>
</head>

<body>
<%
URL = Request.QueryString("URL")
If Len(URL) = 0 Then URL = http://www.mywebsite.com ' The default URL
name=request.form("Sendersname")
from=request.form("SendersEmail")
message=Request.Form("Message")
If Len(Request.Form("SendersEmail")) > 0 Then ' Time to send the emails
Dim objMail,FriendEmail,I
sBody = "This Page at " & URL & " has been recommended by " & name & " at " & Request.Form("SendersEmail") & vbCrLf & " <-- Message For You--> " & vbcrlf & message
I=0

' Loop until no more email addresses are given.
Do While True
FriendEmail = Request.Form("FriendEmail" & I)
If Len(FriendEmail) = 0 Then
Exit Do
Else
Set objMail = CreateObject("CDONTS.NewMail")
objMail.From = name 
objMail.Subject = "Recommended Page"
objMail.Importance=1
objMail.Body = sBody
objMail.To = FriendEmail
objMail.Send()
End If
I=I+1
Loop

Set objMail = Nothing%>

<%
Response.write "<center> <font color=#FFFFFF><H1>Thank you for Recommending us to Your Friends.</H1>"%>


<%
Response.write "<a href=" & URL & " style='color: #ffffff'>Click here to return to " & URL & "</a></font></center>"
Else
%>

<form method="POST" action="mail.asp?URL=<%= URL %>">
<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td><b><font color="#FFFFFF">Recommended URL:</font></b> &nbsp;</td>
<td><p><font color="#FFFFFF"> <%= URL %></font></p>
</td>
</tr>
<tr>
<td><b><font color="#FFFFFF">Your Name:</font></b> </td>
<td><input type="text" name="Sendersname" size="25"></td>
</tr>
<tr>
<td><b><font color="#FFFFFF">Your Email:</font></b> </td>
<td><input type="text" name="SendersEmail" size="25"></td>
</tr>
<tr>
<td><b><font color="#FFFFFF">Your friends emails.</font></b></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><font color="#FFFFFF">1.</font> </td>
<td> <input type="text" name="FriendEmail0" size="29"></td>
</tr>
<tr>
<td><font color="#FFFFFF">2.</font></td>
<td><input type="text" name="FriendEmail1" size="29"></td>
</tr>
<tr>
<td><font color="#FFFFFF">2.</font></td>
<td><input type="text" name="FriendEmail2" size="29"></td>
</tr>
<tr>
<td><font color="#FFFFFF">2.</font></td>
<td><input type="text" name="FriendEmail3" size="29"></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><b><font color="#FFFFFF">Message</font></b></td>
<td><textarea rows="6" name="Message" cols="41"></textarea></td>
</tr>
<tr>
<td colspan="2">
<p align="center"><br>
<input type="submit" value="Tell a Friend"><br>
<br>
</p>
</td>
</tr>
</table>

</form>
<% End If %>
</td>
</tr>
</table>
</body>
</html>

That is all you have to do.. using this example you can send mail to multiple friends at a time with one click.




Added on May 29, 2007 Comment
}