<form method=post action=tellck.php>
<table border="0" cellpadding="0" cellspacing="0"
align=center>
<tr bgcolor='#f1f1f1'><td colspan=2 align=center><font
face='Verdana' size='2' ><b>TELL A
FRIEND</b></font></td></tr>
<tr><td width=100><font face='Verdana' size='2' >Your
Name</font></td><td width=200><input type=text name=y_name></td></tr>
<tr bgcolor='#f1f1f1'><td><font face='Verdana' size='2'
>Your Email</font></td><td><input type=text name=y_email></td></tr>
<tr ><td><font face='Verdana' size='2' >Your Friend's
Name</font></td><td><input type=text name=f_name></td></tr>
<tr bgcolor='#f1f1f1'><td><font face='Verdana' size='2'
>Friend's Email</font></td><td><input type=text name=f_email></td></tr>
<tr ><td><font face='Verdana' size='2' >Your
Message</font></td><td><textarea name=y_msg rows=5
cols=20></textarea></td></tr>
<tr bgcolor='#f1f1f1'><td colspan=2 align=center><font
face='Verdana' size='2' ><input type=submit
value='Send'></font></td></tr>
</table>
</form>
You can see this from submits the details to tellck.php page. Here is the code to post the details to friends email address. Use the form at the end of this page to test the script.
$ref=@$HTTP_REFERER; // Change this line to
$ref="https://www.plus2net.com/php_tutorial/tell_friend.php"; // Add your URL here
tellck.php
<?Php
$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 (strlen($y_name) <2 ) { // checking your name
$msg .="Please enter your name<BR>";
$status= "NOTOK";}
if(!filter_var($y_email,FILTER_VALIDATE_EMAIL)){ // Your email validation
$msg .="Your email address is not valid<BR>";
$status= "NOTOK";
}
if (strlen($f_name) <2 ) { // checking freinds name
$msg .="Please enter your friend's name<BR>";
$status= "NOTOK";}
if(!filter_var($f_email,FILTER_VALIDATE_EMAIL)){ // Friends email validation
$msg .="Your Friends Email address is not correct<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 //////////////
$ip=$_SERVER['REMOTE_ADDR']; // Collect the IP address of visitor
$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 the page at n $ref n";
/// Body message prepared with the message entered by the user ////
$body_message =$header_message."n".$y_msg."n";
// IP address of visitor is added to message, you can remove it if not required.//
$body_message .="n n $ip n This is a free script from https://www.plus2net.com";
//// Mail posting part starts here /////////
$headers="";
//$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($f_email,$subject,$body_message,$headers);
////// Mail posting ends here ///////////
echo "<center><font face='Verdana' size='2' color=green>Thank You, Your message posted 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 <br><br><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);'></font></center>";
}
?>
<?Php
$ip=$_SERVER['REMOTE_ADDR'];
if(strlen($ip) > 3){
echo "Your IP address=$ip";
}
?>
We have stopped the demo of this script. You can download and try at your end.
TELL A FRIEND | |
Your Name | |
Your Email | |
Your Friend's Name | |
Friend's Email | |
Your Message (Editing of text area is disabled. You can use it after downloading the script) | |
sanzeev | 12-03-2010 |
really nice script thanks for this |
sheepiboy | 31-05-2010 |
Dears, how to modify the tell a friend script because the ref ulr is not linked, just only a simple text, thank you. |
Very good!!! | 17-11-2012 |
Thanks m8! This helped me alot! Great tutorial |
27-02-2023 | |
How can I use this script with the function so it forces visitors to refer 5 friends no bypass? That would be Great |
27-02-2023 | |
A redirection to choosen page after submission would also be great |