Christina
Новичок
Дата регистрации:
23.03.2014 14:46:36
Сообщений: 1
<?php
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['formid'] == 'contactsform'
{
$mailto = mailto:'[email protected]';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Reception';
$message = 'Контактная информация с сайта:';
$success_url = 'contacts.php';
$error_url = 'contacts.php';
$error = '';
$mysql_server = 'localhost';
$mysql_database = 's-a_';
$mysql_table = 'anketa2_';
$mysql_username = '';
$mysql_password = '';
$eol = "\n";
$max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;
$boundary = md5(uniqid(time()));
$header = 'From: '.$mailfrom.$eol;
$header .= 'Reply-To: '.$mailfrom.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
if (!empty($error))
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $error, $errorcode);
echo $errorcode;
exit;
}
$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field"
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$message .= $eol;
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (!is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
}
}
}
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=utf8'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($message).$eol;
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)
{
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
}
}
}
$body .= '--'.$boundary.'--'.$eol;
if ($mailto != ''
{
mail($mailto, $subject, $body, $header);
}
$search = array("ä", "Ä", "ö", "Ö", "ü", "Ü", "ß", "!", "§", "$", "%", "&", "/", "\x00", "^", "°", "\x1a", "-", "\"", " ", "\\", "\0", "\x0B", "\t", "\n", "\r", "(", "", "=", "?", "`", "*", "'", ":", ";", ">", "<", "{", "}", "[", "]", "~", "²", "³", "~", "µ", "@", "|", "<", "+", "#", ".", "´", "+", ","
$replace = array("ae", "Ae", "oe", "Oe", "ue", "Ue", "ss"
foreach($_POST as $name=>$value)
{
$name = str_replace($search, $replace, $name);
$name = strtoupper($name);
$form_data[$name] = $value;
}
mysql_connect($mysql_server, $mysql_username, $mysql_password) or die('Failed to connect to database server!<br>'.mysql_error());
mysql_query("SET NAMES utf8"
mysql_query("CREATE DATABASE IF NOT EXISTS $mysql_database"
mysql_select_db($mysql_database) or die('Failed to select database<br>'.mysql_error());
mysql_query("CREATE TABLE IF NOT EXISTS $mysql_table (ID int(9) NOT NULL auto_increment, `DATESTAMP` DATE, `TIME` VARCHAR(8), `IP` VARCHAR(15), `BROWSER` TINYTEXT, PRIMARY KEY (id))"
foreach($form_data as $name=>$value)
{
mysql_query("ALTER TABLE $mysql_table ADD $name VARCHAR(255)"
}
mysql_query("INSERT INTO $mysql_table (`DATESTAMP`, `TIME`, `IP`, `BROWSER`)
VALUES ('".date("Y-m-d"."',
'".date("G:i:s"."',
'".$_SERVER['REMOTE_ADDR']."',
'".$_SERVER['HTTP_USER_AGENT']."'"or die('Failed to insert data into table!<br>'.mysql_error());
$id = mysql_insert_id();
foreach($form_data as $name=>$value)
{
mysql_query("UPDATE $mysql_table SET $name='".mysql_real_escape_string($value)."' WHERE ID=$id" or die('Failed to update table!<br>'.mysql_error());
}
mysql_close();
header('Location: '.$success_url);
exit;
}
?>