<?php
/* =========================================
Simple PHP Form Mailer by Kalinga Athulathmudali
mail.php
Last Edit 2007-Mar-27
Version 1.9.4
Web Site http://www.onetforum.com/formmailer/
Copyright (C) 2007 Kalinga Athulathmudali
=========================================
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
########################## DO NOT EDIT ###############################
# Turn off all error reporting
error_reporting(0);
require "config.php";
# Script Ver = DO NOT EDIT =
$ver = "Ver 1.9.4";
session_start(img);
$data_error = 1;
# Get the HTTP Post Data form the HTML form
foreach ($_POST as $key => $val){
# If there is a feild call email and if its blank, the system use the $from email as a the form email #
if($key=="email" && $val!=""){
$from=$val;
}
# If there is a feild call redirect & not blank, the system use the redirect it to the page
if($key=="redirect" && $val!=""){
$send_page=$val;
}
# If there is a feild call subject & not blank, the system use the subject field as the email subject
if($key=="subject" && $val!=""){
$subject=$val;
}
# getting the key form the form sec key #
if ($key == "key") {
$sec_key = $val;
}
# Maske sure not to add the submit botton or key field info and other junk to the email
if($val!="Submit" && $key!="key" && $key!="B1" && $key!="PHPSESSID" && $key!="redirect" && $key!="required" && $key!="recipient" && $key!="subject"){
# Check if mandatory feild are blank #
for ($i=0; $i < count($form_names); $i++) {
if ($form_names[$i] == $key && $val == ""){
# Java Alert if the mandatory feild are blank #
$msg = "Sorry, $key $field_error";
error_alert($msg, $error_repote, $error_page);
}
}
# check if the form is blank or only got the email field. #
if($val!="" && $data_error=="1" && $key != "email" && $key != "key"){
$data_error = 0;
}
# add each key and var to the html table #
$msg = "$msg <tr><td> $key</td><td> $val</td></tr> \n";
}
}
####################### Image Submit Validation #####################
if ($img_validate == "1") {
$sec_code = $_SESSION['sec_code'];
if (md5($sec_key) != $sec_code){
error_alert($image_error, $error_repote, $error_page);
}
}
######################## DO NOT EDIT #################################
if(!eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $from)){
# Java Alert if the email is invalid #
$msg = "Sorry, $from $email_error";
error_alert($msg, $error_repote, $error_page);
}
# Get user IP and Server Admin email and date #
$id = "<font size='1'> <br><hr size='1'>". $_SERVER['HTTP_USER_AGENT'] ."<br> Client IP = ". $_SERVER['REMOTE_ADDR']."<br><hr size='1'><a href='http://www.onetforum.com/formmailer/'>Sent with Simple PHP Form Mailer $ver </a> on ";
$admin = $_SERVER['SERVER_ADMIN'];
$submit_date = date('F j, Y, g:i a T'). "</font>";
# HTML Tables #
$table_start = "<html><body><div align='center'> <table border='1' id='table1' width='90%'> \n <td align='center'>Key</td><td align='center'>Value</td>";
$table_end = "</table></div><br></body></html>";
# Sending Out the Mail #
if($data_error=="0"){
# Make the form reload if the user come back
$_SESSION['sec_code'] = "NO";
$error="0";
# Message Header Form Mail
$header = "From: <$from>\n";
$header .= "Return-path: <$from>\n";
$header .= "X-Sender-IP: " .$_SERVER['REMOTE_ADDR']."\n";
$header .= "X-Mailer: Simple PHP Form Mailer $ver \n";
$header .= "X-MailerWebSite: http://www.onetforum.com/formmailer/\n";
$header .= "Content-Type: text/html; \n charset=iso-8859-1 \n";
# Message Body
$body = "$table_start $msg $table_end $id $submit_date";
# demo
//$mail_to = "$from";
# Send Mail
send_mail($mail_to, $subject, $body, $sec_local, $header);
# Reply Email #
if ($send_reply == "1") {
# Read the reply email file
$fd=fopen("reply_email.txt","r");
while ($line=fgets($fd,1000))
{
$reply_email_body.=$line;
}
# Close the file after reading it
fclose ($fd);
# if the reply form name is not set the domain name of the site will be used.
if ($reply_email_form_name == ""){
$reply_email_form_name = $_SERVER['HTTP_HOST'];
}
# Message Header Reply Mail
$header = "From: $reply_email_form_name <$reply_email_from>\n";
$header .= "Return-path: <$reply_email_from>\n";
$header .= "X-Reply-To : <$reply_email_from>\n";
$header .= "X-Sender-IP: " .$_SERVER['REMOTE_ADDR']."\n";
$header .= "X-Mailer: Simple PHP Form Mailer $ver \n";
$header .= "X-MailerWebSite: http://www.onetforum.com/formmailer/\n";
$header .= "Content-Type: text/html; \n charset=iso-8859-1 \n";
$reply_email_body .= "<font size='1'><br><hr size='1'><a href='http://www.onetforum.com/formmailer/'>Sent with Simple PHP Form Mailer $ver </a></font>";
# Send Reply Mail
send_mail($from, $reply_email_subject, $reply_email_body, $sec_local, $header);
}
}
else {
# Java Alert if the form is blank #
error_alert($blank_error, $error_repote, $error_page);
$error="1";
}
########################## DO NOT EDIT ###############################
# Error Handling #
if ($error_repote=="0") {
if($error=="0"){
# Redirect the page to the thankyou page.
header ("Location: $send_page");
}
else {
# Redirect the page to the error page.
header ("Location: $error_page");
}
}
else {
if($error=="0"){
# Call the HTML OK Message
disply_error_msg($ok_msg);
}
else {
# Call the HTML Error Message
disply_error_msg($error_msg);
}
}
### Functions ####
########################## DO NOT EDIT ###############################
# Java Alert
function error_alert($msg, $error_repote, $error_page){
# Make the html form to reload
$_SESSION['sec_code'] = "NO";
# Check if error reporint for JS Alert or Page FWD
if ($error_repote == "1"){
# Java Alert
print "<SCRIPT>";
print "alert ('$msg');";
print "history.go(-1);";
print "</SCRIPT>";
die("$msg");
}
else {
#FWD to page
header("Location: $error_page?msg=$msg");
die("$msg");
}
}
########################## DO NOT EDIT ###############################
# HTML Disply Messages
function disply_error_msg($msg) {
echo "<hr width='50%' size='1'>";
echo "<p align=center><b>$msg</b></p>";
echo "<p align=center><a href=javascript:history.go(-1)>Click here to Go Back.</a></p>";
echo "<hr width='50%' size='1'>";
die();
}
########################## DO NOT EDIT ###############################
# Send Mail
function send_mail($mail_to, $subject, $msg, $sec_local, $header){
if ($sec_local == md5($_SERVER['SERVER_SIGNATURE'] + $_SERVER['HTTP_USER_AGENT'])){
mail($mail_to, $subject, $msg, $header);
# Make the html form to reload
$_SESSION['sec_code'] = "NO";
}
else
{
die("Bad Submit");
}
}
?>