|
|
Free tell-a-friend form & script
|
Script updated to v1.3 September 20 2006
Even in this high tech world of web marketing with all sorts
of weird and wonderful tools to assist us in our ecommerce pursuits,
word-of-mouth still remains one of the most powerful tools.
We've been using "tell-a-friend" applications for
a long while now and have found them to be an excellent form of promotion -
I would recommend that every site owner use them.
Even if you only get a couple of people using the script
each day, or even each week for that matter, always bear in mind the
snowball effect. One visitor tells their friends about your site, they tell
their friends, etc. etc. A single visitor has the potential to create
literally thousands of referrals for you!
There's all sorts of recommendation scripts available on the
web, and many you can download for free. Here's one we use on various
sections of our site that we've found to be quite effective. This script
will also notify you of when someone has used the form to recommend your
site to others.
New! need an advanced Tell a Friend script with more
personalization features and a referrer URL function? Try our new
recommendation script - also free!
The following application is in two parts, the script (in
PHP) and the HTML form. There's very little you need to configure.
Note: Frontpage users; when copying the code, first paste it
into Notepad (or similar). If you copy the code directly into the "HTML
View" of FrontPage, you'll end up with some weird characters as well
and the application won't work.
 |
Need a
More Powerful
Tell A Friend application?
* Highly customizable, create forms in seconds
* No complex scripting, spam prevention
* Tracks and monitors usage
* Easy to use admin panel
* Pre-define message
* Or allow users to enter their own
* Free trial, support and much more!..
Try
Tell A Friend King free today! |
|
Step 1 - The Tell a Friend script
Copy and paste the code below (from <?PHP to
?>) into Notepad and then save as "tellafriend.php". The only
items you really need to change are the "$emailto" information and
also your site URL. Both of these are in bold below.
It would also be a good idea to edit the body text of the email
(where indicated below) that will be sent out to recipients with further
details about your site and to alter the subject line in the email the
recipients will receive.
--- do not copy this line, start copying from next line
<?php
// This following statement must be left intact.
// Copyright (c) Michael Bloch and Taming The Beast.
// Tell-A-Friend script V 1.3 Updated September 20 2006
// Taming the Beast.net - http://www.tamingthebeast.net
// Free Web Marketing and Ecommerce articles and tools
// By using this code you agree to indemnify Taming the Beast
// from from any liability that might arise from its use.
// The preceding statement be left intact.
if(count($_POST)) {
# This section nukes nasty code that a malicious
# party may attempt to inject into the form
foreach(array('friendmail1','friendmail2','friendmail3','email','name') as $key) $_POST[$key] = strip_tags($_POST[$key]);
if(!is_secure($_POST)) { die("Asta la vista Hacker");}
# This section sends an email to you when
# the form is used
// Your email address (for copies to be sent to you)
$emailto = "you@yoursite.com";
// Your email subject text
$esubject = "A page has been sent";
// The email text for copies sent to you
$emailtext = "
$_POST[name] has used the tell-a-friend form. Their email address is $_POST[email]
The people they have recommended your site to are:
$_POST[friendmail1]
$_POST[friendmail2]
$_POST[friendmail3]
";
# This sends the email to you
@mail("$emailto", $esubject, $emailtext, "From: $_POST[email]");
# This section sends to the recipients
// Target page after successful submission
// Change thankyou.htm to suit
$thankyoupage = "thankyou.htm";
// Change the subject text below to suit
$tsubject = "A web site recommendation from $_POST[name]";
// Change the text below for the email
// Don't change any "$_POST[value]" items
$ttext = "
Hi,
A friend or colleague of yours, $_POST[name] , whose email address is $_POST[email] thought you may like to visit our site.
$_POST[name] has used our Tell-a-Friend form to send you this email.
http://www.yoursite.com
";
# This emails the recommendation to the addresses submitted
@mail("$_POST[friendmail1],$_POST[friendmail2],$_POST[friendmail3]", $tsubject, $ttext, "FROM: $_POST[email]");
# After successful processing, the thank you page
header("Location: $thankyoupage");
exit;
}
# Don't change anything below
function is_secure($ar) {
$reg = "/(Content-Type|Bcc|MIME-Version|Content-Transfer-Encoding)/i";
if(!is_array($ar)) { return preg_match($reg,$ar);}
$incoming = array_values_recursive($ar);
foreach($incoming as $k=>$v) if(preg_match($reg,$v)) return false;
return true;
}
function array_values_recursive($array) {
$arrayValues = array();
foreach ($array as $key=>$value) {
if (is_scalar($value) || is_resource($value)) {
$arrayValues[] = $value;
$arrayValues[] = $key;
}
elseif (is_array($value)) {
$arrayValues[] = $key;
$arrayValues = array_merge($arrayValues, array_values_recursive($value));
}
}
return $arrayValues;
}
?>
--- do not copy this line, finish copying at line
above
Step 2 - The tell a friend form:
Copy and paste the code below and save it as recommend.htm
(or whatever other name you like). This is the actual form that visitors
will complete to recommend your site to others. Ensure you save the file
into the same folder as where the tellafriend.php script will be and
customize the page to suit your site.
<html>
<head>
<title>tell a friend</title>
<script language="javascript">
<!--
function reset() {
document.tellafriend.name.value="";
document.tellafriend.email.value="";
document.tellafriend.friendmail1.value="";
document.tellafriend.friendmail2.value="";
document.tellafriend.friendmail3.value="";
}
function validate() {
if (document.tellafriend.friendmail1.value.length==0) {
alert("please enter your friend's email address");
return false;
}
if (document.tellafriend.email.value.length==0) {
alert("please enter your email address");
return false;
}
if (document.tellafriend.name.value.length==0) {
alert("please enter your name");
return false;
}
document.tellafriend.submit()
return true;
}
//-->
</script>
</head>
<body onload="reset()" topmargin="0" leftmargin="0">
<center>
</center>
<table width="450" cellpadding="0" cellspacing="0" align="center">
<tr valign="top">
<td valign="middle" align="center">
<p>Complete the details below to send our link to your friends.</p>
<form name="tellafriend" action="tellafriend.php" method="post" onsubmit="return checkfields()">
<div align="center">
<center>
<table border="0" cellpadding="10" cellspacing="0">
<tr>
<td> *your name:</td>
<td>
<input size="30" name="name" maxlength="45">
</td>
</tr>
<tr>
<td>*your email:</td>
<td>
<input size="30" name="email" maxlength="45">
</td>
</tr>
<tr>
<td colspan="2">
<p align="center">please enter your friend's email addresses:</td>
</tr>
<tr>
<td>*email 1:</td>
<td>
<input size="30" name="friendmail1" maxlength="45">
</td>
</tr>
<tr>
<td>email 2:</td>
<td>
<input size="30" name="friendmail2" maxlength="45">
</td>
</tr>
<tr>
<td>email 3:</td>
<td>
<input size="30" name="friendmail3" maxlength="45">
</td>
</tr>
<tr>
<td colspan="2">
<p align="center">
The email that will be sent will contain your name and email address. <br>
<input onclick="validate();" type="button" value="click here to send">
</td>
</tr>
</table>
</center>
</div>
</form>
</td>
</tr>
<tr valign="top">
<td valign="middle" align="center">
</td>
</tr>
</table>
</body>
</html>
Once you have these two files prepared, create a thankyou.htm
page, upload them all to your
site and you should be ready to go!
Be
notified of Tell a Friend script updates!
Don't forget to sign up for our free newsletter to be informed of
Tell a friend script updates and new features! Simply enter your
name and email address at the top right hand side of this page! |
Using the form with a popup
You may not wish to send your visitors to another page to
complete the tell-a-friend form. If you would like to call the form via a
popup, use this code:
Click the "Select All"
button and then copy the code - Change the
"pathto/recommend.htm" statement in the code to suit. Experiment
with the the
size of the popup window by changing width and height attributes.
Tip: get news of any updates to this Tell-a-friend
script by subscribing to our free newsletter via the box on the top right
hand side of this page!
Questions?
Unfortunately I don't have the time available to me to
answer individual questions about the script; but check this blog
post thread for other troubleshooting tips. Thanks!
Other learning resources
Advanced
tell a friend script
Live chat software and
services guide - try a free trial
Creating custom
error pages
Guide to selecting
shopping carts
Michael Bloch
Taming the Beast
http://www.tamingthebeast.net
Tutorials, web content, tools and software.
Web Marketing, Internet Development & Ecommerce Resources
____________________________
This article is not available for reproduction without express written
permission. Details regarding articles that are available for reproduction
without written consent can be viewed in our tutorial
archive.
Click here to view article index
|