/******************************************************************************
* Tell A Friend Script:
* This script allows your visitors to sent invitation to their friends via email to visit your site.
*
* Usage:
* The script comes with three files tell_a_friend.php, thankyou.html and install.txt
* You're NOT allowed to redistribute or sell this script.
* You are allowed to modify this script for your own personal use.
* Please see install.txt attached in the zip for installation instructions.
*
* Notes:
* If you like this script or used it for your website or project.
* Please remember too link back to www.php-learn-it.com.
* Your help is always appreciated.
*
* author: webdev (php-learn-it.com (or phplearnit.com)
* Visit www.php-learn-it.com (or www.phplearnit.com) for more script and tutorials on PHP.
*****************************************************************************/
//minimum characters allowed in the message box
$msg_min_chars = "10";
//maximum characters allowed in the message box
$msg_max_chars = "250";
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
$errors = array();
function validate_form_items()
{
global $msg_min_chars, $msg_max_chars;
$msg_chars = "{".$msg_min_chars.",".$msg_max_chars."}";
$form_items = array(
"name" => array(
"regex" => "/^([a-zA-Z '-]+)$/",
"error" => "Your name appears to be in improper format",
),
"email" => array(
"regex" =>
"/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/",
"error" => "email address is invalid",
),
"message" => array(
"regex" => "/.*/",
"error" => "Your message is either too short or exceeds $msg_max_chars characters",
),
);
global $errors;
if(!preg_match($form_items["name"]["regex"], $_POST["your_name"]))
$errors[] = $form_items["name"]["error"];
if(!preg_match($form_items["email"]["regex"], $_POST["your_email"]))
$errors[] = "your ".$form_items["email"]["error"];
if(!preg_match($form_items["email"]["regex"], $_POST["friend_email1"]))
$errors[] = "Friend 1 ".$form_items["email"]["error"];
if(strlen(trim($_POST["message"])) < $msg_min_chars || strlen(trim($_POST["message"])) > $msg_max_chars )
$errors[] = $form_items["message"]["error"];
if(trim($_POST["friend_email2"]) != "")
{
if(!preg_match($form_items["email"]["regex"], $_POST["friend_email2"]))
$errors[] = "Friend 2 ".$form_items["email"]["error"];
}
if(trim($_POST["friend_email3"]) != "")
{
if(!preg_match($form_items["email"]["regex"], $_POST["friend_email3"]))
$errors[] = "Friend 3 ".$form_items["email"]["error"];
}
return count($errors);
}
function email($from, $from_name, $to, $message)
{
//header("Location: success.html");return;
$headers .= "From: ".$from."\r\n";
$headers .= "Content-type: text/plain; charset=ISO-8859-1";
$your_domian_name = "www-genericpharmacy.com";
//edit what you want your vistors to see in their email here
$subject = $from_name." I thought you would like: $your_domian_name";
$your_message = "Hi!\r\n";
$your_message.= ucfirst($from_name);
$your_message.= " wants you to check out $your_domian_name\r\n";
$your_message.= "Sender's Message:\n\r";
$message=$your_message.stripslashes($message);
if (mail($to,$subject,$message,$headers) ) {
return true;
} else {
return false;
}
}
function print_error($errors)
{
foreach($errors as $error)
{
$err.=$error."
";
}
echo
"