Create Tell A Friend script with HTML & PHP

Tell a Friend Printscreen

Final result HERE

Today we learn how to create a TELL A FRIEND script with HTML and PHP. If you want to exercise on my files, click here
to download them!
[1] First we have to create two files, index.php and tellck.php! The first is index.php where we create a form, we put
an background image and a bookmark image to look more pretty.

<html>
<head>
<title>Tell a friend</title>
</head>
<body background=”bg.gif”>
<center><img src=”bookmark.png” mce_src=”bookmark.png”>
<form action=”tellck.php” method=”post”>
<pre>
Your Name
<input type=”text” name=”y_name” value=”"><br>
Your Email
<input type=”text” name=”y_email” value=”"><br>
Your Friend’s Name
<input type=”text” name=”f_name” value=”"><br>
Friend’s Email
<input type=”text” name=”f_email” value=”"><br>
Message
<textarea name=”y_msg” cols=”60″ rows=”6″></textarea><br><br>
<input type=”submit” name=”Send” value=”Send”><input type=”reset” name=”Clear” value=”Clear”>
</center>
</form>
</body>
</html>

Save this like index.php

[2] In this step we have to create tellck.php

<html>
<head>
<title>Tell a friend</title>
</head>
<body bgcolor=”#ffffff” text=”#000000″ link=”#0000ff” vlink=”#800080″ alink=”#ff0000″>
<?
$status = “OK”;
$msg=”";
$y_email=$_POST['y_email'];
$y_name=$_POST['y_name'];
$f_email=$_POST['f_email'];
$f_name=$_POST['f_name'];
$y_msg=$_POST['y_msg'];
if(substr_count($y_email,”@”) > 1 or substr_count($f_email,”@”) > 1){
$msg .=”Use only one email address<BR>”;
$status= “NOTOK”;
}
if (!stristr($y_email,”@”) OR !stristr($y_email,”.”)) { // checking your email
$msg .=”Your email address is not correct<BR>”;
$status= “NOTOK”;}
if (strlen($y_name) <2 ) { // checking your name
$msg .=”Please enter your name<BR>”;
$status= “NOTOK”;}
if (!stristr($f_email,”@”) OR !stristr($f_email,”.”)) { // checking friends email
$msg .=”Your Friends address is not correct<BR>”;
$status= “NOTOK”;}
if (strlen($f_name) <2 ) { // checking freinds name
$msg .=”Please enter your friend’s name<BR>”;
$status= “NOTOK”;}
if (strlen($y_msg) <2 ) { // checking Message details
$msg .=”Please enter your message details<BR>”;
$status= “NOTOK”;}
if($status==”OK”){ // all validation passed
/////////// Sending the message starts here //////////////
$ref=@$HTTP_REFERER;
/////Message at the top of the page showing the url////
$header_message = “Hi $f_name \n Your friend $y_name requested you to visit this page http://www.piticstyle.com”;
/// Body message prepared with the message entered by the user ////
$body_message =$header_message.”\n”.$y_msg.”\n”;
$body_message .=”";
//// Mail posting part starts here /////////
$headers=”";
//$headers = “Content-Type: text/html; charset=iso-8859-1\n”.$headers;
// Un comment the above line to send mail in html format
$headers4=$y_email; // Change this to change from address
$headers.=”Reply-to: $headers4\n”;
$headers .= “From: $headers4\n”;
$headers .= “Errors-to: $headers4\n”;
$subject=”Request to visit URL”;
mail($f_email,$subject,$body_message,$headers);
////// Mail posting ends here ///////////
echo “<center><font face=’Verdana’ size=’2′ color=green>Thank You, Your message was send to $f_name</font></center>”;
//////////// Sending the message ends here /////////////
}else{// display the error message
echo “<center><font face=’Verdana’ size=’2′ color=red>$msg</font></center>”;
}
?>
</body>
</html>

That’s it. To test the result you need to upload this files on a server because the e-mail function don’t work on a localhost! Search on internet websites who give freehosting! Thank you! Final result here


Tags: , , , , , , , , , , , , ,

7 Responses to “Create Tell A Friend script with HTML & PHP”

  1. nookli » Blog Archive » Create Tell A Friend script with HTML & PHP Says:

    [...] here for full story This entry was posted on Saturday, October 27th, 2007 at 7:55 am and is filed under [...]

  2. Arpan Says:

    have a look at siphs.com. You can be up and running in less than 10 minutes, and you can customize the look and feel of your tell-a-friend emails to match the branding of your site.

  3. Farrhad Says:

    Very good script

  4. Atilla Says:

    Can’t get this to work. I made the 2 file uploaded them but once i press submit its just not working. Any chance of getting these files in a zip file or something to download as i can’t grab the demo version you have. Really nice and simple script would really appreciate it. thanks.

  5. Arpan Says:

    Hi Atilla,

    Try this one here:
    http://www.siphs.com/get_the_siphsmail_button.jsp

    It’s simply cut&paste of javascript and if you want to have the emails that are sent match the look and feel of your site, you can do that too. Heck, if the New York Times does, this, why can’t you?

    -Arpan

  6. Polymath Says:

    Won’t work for you because the above script uses ’ ′ instead of ‘ and “ “ instead of ” ” so it is useless until changed.

  7. Polymath Says:

    wow. Actually this site changes how ” and “” is posted. So the original is probably fine but the copy and paste is not.

Leave a Reply