Subscribe to get design
tips, latest trends, free
stuff and more.
It doesn't look like an e-mail address


  Web Programming PHP Create Tell A Friend Script with HTML & PHP

Create Tell A Friend Script with HTML & PHP

PiticStyle PHP Jun 12, 2008

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.

<title>Tell a friend</title>
<body background="bg.gif">
<center><img src="/img_articles/15098/bookmark.png" mce_src="/img_articles/15098/bookmark.png">
<form action="tellck.php" method="post">
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>
<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">

Save this like index.php

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

<title>Tell a friend</title>
<body bgcolor="#ffffff" text="#000000� link="#0000ff" vlink="#800080� alink="#ff0000�>
$status = "OK";
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 //////////////
/////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";
/// 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 = "Content-Type: text/html; charset=iso-8859-1n".$headers;
// Un comment the above line to send mail in html format
$headers4=$y_email; // Change this to change from address
$headers.="Reply-to: $headers4n";
$headers .= "From: $headers4n";
$headers .= "Errors-to: $headers4n";
$subject="Request to visit URL";
////// 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>";

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!

Create Tell A Friend Script with HTML & PHP

subscribe to newsletter