<?php
// Page Referral program

$websitename = "Bev's Country Cottage";
$websiteadminemail = "bevq@bevscountrycottage.com";

$action = $_POST['action'];
if ($action == "Send") {
    $referrer = $_POST['referrer'];
	$fromname = $_POST['fromname'];
    if (strstr($fromname,"http:")) die();
    if (strstr($fromname,"href")) die();
    if (empty($fromname)) die("Oops, you must include a valid name.  Use your browser back button to go back to the form.\n");
	$fromemail = $_POST['fromemail'];
    if (empty($fromemail)) die("Oops, you must include a valid email address.  Use your browser back button to go back to the form.\n");
    if (!empty($fromemail) && !strstr($fromemail,"@")) die("Oops, you must include a valid email address.  Use your browser back button to go back to the form.\n");
	$toname = $_POST['toname'];
    if (strstr($toname,"http:")) die();
    if (strstr($toname,"href")) die();
    if (empty($toname)) die("Oops, you must include a valid name.  Use your browser back button to go back to the form.\n");
	$toemail = $_POST['toemail'];
	$subject = "Webpage Recommendation from your friend $fromname";
    $message = "Dear $toname,\n\nYour friend $fromname would like you to see a web page they viewed today.  Please go to\n\n$referrer\n\nBest Wishes,\n\n$websitename";
    $ret = mail($toemail, $subject, $message, "From: $websitename<$websiteadminemail>");	
?>
<h2><img src="images/ch1cl22d.gif" width="198" height="192" align="middle" />Thank You!</h2>
<p>Thanks for referring our website.  Click <a href="<?php echo $referrer; ?>">here</a> to return to the Page. 
  </body>
  </html>
  <?php
} else {
    $referrer = getenv("HTTP_REFERER");
?>
You can send a referral to your friend about the page you were just looking at on Bev's Country Cottage!  </p>
<p><img src="images/cutecolorsfish6.gif" width="113" height="75" />Please fill out all fields<br>
  in this form and click on the "Send" button.</p>
<p>
<form method=POST action=referral.php>
<input type="hidden" name="referrer" value="<?php echo $referrer; ?>">
<table border=0>
<tr><td align=right>Your Name:</td><td align=left><input type=text name=fromname size=50 max=50></td></tr>
<tr><td align=right>Your Email:</td><td align=left><input type=text name=fromemail size=50 max=50></td></tr>
<tr><td align=right>Your Friend's Name:</td><td align=left><input type=text name=toname size=50 max=50></td></tr>
<tr><td align=right>Your Friend's Email:</td><td align=left><input type=text name=toemail size=50 max=50></td></tr>
<tr><td></td><td><input type=submit name=action value=Send></td></tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
}
?>
