PHP Send-Mail: The ultimate script. If you are tired of spam, or are confused about various security issues related to your cgi-mail or are frustrated with having to configure things like cgi email handlers written in perl, then this simple PHP Mail Script might be for you.
This mail script, written in PHP, is fast and light. It records the ip address of the one filling it out so that you can track who uses your form.
It also strips out malicious coding from any of the would-be script kiddies that are out there.
// Configuration Settings
$SendFrom = “YourBusiness.com “;
$SendTo = “You@example.com”;
$SubjectLine = “fill your subject line in here”;
$ThanksURL = “http://www.example.com/thankyou.htm”; //confirmation page
$Divider = “~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~”;
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($_SERVER[“REMOTE_ADDR”]) . “n$Dividern”;
foreach ($_POST as $Field=>$Value)
$MsgBody .= “$Field: $Valuen”;
$MsgBody .= “$Dividern” . $_SERVER[“HTTP_USER_AGENT”] . “n”;
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
$Spam = count($_POST) == 0 || stristr($MsgBody, “cc: “) ||
stristr($MsgBody, “href=”) || stristr($MsgBody, “[url”);
if (!$Spam)
mail($SendTo, $SubjectLine, $MsgBody, “From: $SendFrom”);
header(“Location: $ThanksURL”);
?>
Save the code above to a text editor and name it as contact.php. Next, you’ll want to fill in the configuration setting to reflect your own domain email, business and so on. You can also designate a thank you page that the script will send your visitor to once the send button has been clicked.
Configure your form like this;
form action=”contact.php” method=”post”
Upload your PHP contact.php to the directory/folder that your contact form page resides in, and you should be good to go.
This script will send mail to and from your domain .. you can’t use it to send mail to any other domain, and free email address configurations won’t work. The script logs the ip address of the one that uses your form, so that it will be easier for you to determine whether or not the person using it needs to be blocked via their ip address in your .htaccess file.
You can build any kind of form, from surveys to job applications and this script will work on all of them .. it’s handy, simple, and very fast.