$intro";
}
else {
$msg .= "$intro\n";
}
foreach ($_POST as $key => $string) {
$posted[] = $key;
if (!is_array($string)) {
$value = stripslashes($string);
}
else {
$arrayCount = count($string);
$oldValue = NULL;
foreach ($string as $arrayKey => $arrayValue) {
$oldValue .= $arrayValue . ', ';
}
$value = $oldValue;
}
if (in_array($key,$formval) && ($value == NULL || $value == '')) {
$results[] = ucfirst($key) . " cannot be blank!";
$bademail = true;
}
if ($key == "email" && !check_email_address($value)) {
$results[] = "Invalid email address!";
$bademail = true;
}
if($key == "security_code" && $value != ($_SESSION['security_code'])) {
$results[] = "Wrong security code!";
$bademail = true;
}
if ($key != "security_code" && $key != "submit" && $key !="MAX_FILE_SIZE" && $key != "message") {
if ($html == 1) {
$msg .= ucfirst($key) . " : " . $value . "
";
}
else {
$msg .= ucfirst($key) . " : " . $value . "\n";
}
}
if ($key == "name") {
$name = $value;
}
if ($key == "email") {
$headers = "From: " . $name . " <" . $value . ">\n";
$headers .= "Reply-To: " . $value . "\n";
$headers .= "Return-Path: " . $value . "\n";
$headers .= "Envelope-from: " . $value . "\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
}
if ($key == "message") {
$message = "\n\n$value\n";
}
}
foreach ($formval as $string) {
if (!in_array($string,$posted)) {
$results[] = ucfirst($string) . " cannot be blank!";
$bademail = true;
}
}
$msg .= $message;
if ($attachments == 0) {
$msg .= "--$boundary--\n";
}
else if (isset($_FILES['attachment']) && $attachments == 1) {
foreach ($_FILES["attachment"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
echo"$error_codes[$error]";
if (move_uploaded_file($_FILES["attachment"]["tmp_name"][$key], 'tmp/' . $_FILES["attachment"]["name"][$key]) or die("Problems with upload")) {
$file_upload = true;
$tmp_path = 'tmp/' . $_FILES["attachment"]["name"][$key];
$file = fopen($tmp_path,'rb');
$data = fread($file,filesize($tmp_path));
fclose($file);
}
$attachment = chunk_split(base64_encode($data));
$attachment_name = $_FILES['attachment']['name'][$key];
$attachment_type = $_FILES['attachment']['type'][$key];
$attachment_size = $_FILES['attachment']['size'][$key];
$file_extension = strtolower(substr(strrchr($attachment_name,"."),1));
$msg .= "\n--$boundary\n";
$msg .= "Content-Type: $attachment_type; name=\"$attachment_name\"\n";
$msg .= "Content-Transfer-Encoding: base64\n";
$msg .= "Content-Disposition: attachment; filename=$attachment_name\n\n\n";
$msg .= "$attachment\n";
}
}
}
if ($attachments == 1 && $attachment_size > $max_file_size && $file_upload == true) {
$results[] = 'The uploaded file size is too big!';
}
else if ($attachments == 1 && !in_array($file_extension, $file_types) && $file_upload == true) {
$results[] = 'The uploaded file type is not an acceptable type!';
}
else if ($emailval == 1) {
if ($bademail != true) {
mail($to, $subject, $msg, $headers);
$results[] = 'Thank You! Your message has been submitted!';
}
}
if ($logging == 1) {
$timestamp = date('Y-m-d');
foreach ($_POST as $key => $string) {
$value = stripslashes($string);
if ($key == 'security_code') {
$logmsg .= ucfirst ($key) . " : Submitted: " . $value . " => Required: " . $_SESSION['security_code'] . "\n";
}
else {
$logmsg .= ucfirst ($key) . " : " . $value . "\n";
}
}
$logmsg .= "\n";
if (isset($_FILES["attachment"]["error"])) {
foreach ($_FILES["attachment"]["error"] as $filekey => $fileerror) {
if ($fileerror == UPLOAD_ERR_OK) {
$logmsg .= "Attachment " . $filekey . " : " . $_FILES["attachment"]["name"][$filekey] . "\n";
}
}
}
$logmsg .= "\n";
if ($bademail == true) {
foreach ($results as $result) {
$logmsg .= "Error : " . $result . "\n";
}
$logmsg .= "\n";
}
$logmsg .= "Referrer : " . $_SERVER['HTTP_REFERER'] . "\n";
$logmsg .= "User Agent : " . $_SERVER['HTTP_USER_AGENT'] . "\n";
if (file_exists($logpath . $timestamp . '.txt')) {
$fh = fopen($logpath . $timestamp . '.txt', 'a+') or die( "Error opening file" );
}
else {
$fh = fopen($logpath . $timestamp . '.txt', 'w') or die( "Error opening file" );
}
if (!fwrite($fh, $logmsg)) { die( "Error writing to file!" ); }
if (!fwrite($fh, "\n---------------\n\n")) { die( "Error writing to file!" ); }
fclose($fh) or die( "Error closing file!" );
}
session_unregister(security_code);
}
if (file_exists($tmp_path)) {
unlink($tmp_path);
}
if (!empty($results)) {
echo '
';
foreach ($results as $result) {
echo '- ' . $result . '
';
}
echo '
';
$errors = '';
}
if ($handle = opendir('tmp/')) {
while (false !== ($file = readdir($handle))) {
if (is_file('tmp/' . $file)) {
unlink('tmp/' . $file);
}
}
closedir($handle);
}
?>