PHP Tutorial : Tell a friend script

Hi,

In this php tutorial I’ll teach you how to create a simple tell a friend script. Basically, it will use what you learned in the send email with a contact form script, but in this case we’ll choose the destination and also the “from:” field which we’ll setup on php mail() function headers.

<form action="" method="post">
Your email address : <input type="text" name="yemail"><br/>
Your friend's email address : <input type="text" name="femail"><br/>
Your message :
<textarea name="text">Hey look what nice website I found
<?=$_SERVER['SERVER_NAME'];?>
</textarea>
<input type="submit" name="sb" id="sb" value="Tell a friend">
</form>
<?php
//check if tell a friend form was completed and sended


if(isset($_POST['sb'])) {

if($_POST['yemail'] == "" || $_POST['femail'] == "" || $_POST['text'] == "") {

print "All fields are mandatory";
}else{
$to = $_POST['femail'];
$from = "From : $_POST[yemail]";
$message = $_POST['text'];
$subject = "Your friend tells u";
mail($to, $subject , $message, $from);
}
}
?>

One Response to “PHP Tutorial : Tell a friend script”

  1. mohamed elkebir Says:

    I Think You’re A Good Webmaster, It’s Hard To Find The Simple Way To Teach People Somethings Like this Script, I Have To Say WOW!!!


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>