<?php // RAY_form_to_email.php
error_reporting(E_ALL);
// SEND MAIL FROM A FORM
// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
$str = stripslashes($str);
$str = trim(preg_replace("/ +/", " ", $str));
$str = preg_replace('/^ a-zA-Z0-9&+:?_\.\-/', '', $str);
return $str;
}
// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from = "[email protected]";
$subj = "Contact Form";
// THIS IS AN ARRAY OF RECIPIENTS
$to[] = "[email protected]";
$to[] = "[email protected]";
$to[] = "[email protected]";
// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
// CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
$email = clean_string($_POST["email"]);
$name = clean_string($_POST["name"]);
$telephone = clean_string($_POST["telephone"]);
// CONSTRUCT THE MESSAGE
$content = '';
$content .= "You have a New Query From $name \n\n";
$content .= "Tel No: $telephone\n";
$content .= "Email: $email\n";
// SHOW THE NEW WEB PAGE
echo "<h1>THIS IS THE ACTION PAGE</h1>";
// SEND MAIL TO EACH RECIPIENT
foreach ($to as $recipient)
{
if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
{
echo "<br/>MAIL FAILED FOR $recipient";
}
else
{
echo "<br/>MAIL WORKED FOR $recipient";
}
}
} // END OF PHP - PUT UP THE FORM
?>
<form method="post">
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name: <input name="name" />
<br/><input type="submit" />
</form>
|