<?php
chdir('..');
	require_once('api/Simpla.php');
	$simpla = new Simpla();
	$simpla->db->connect();

$subject = 'Новый отзыв с ' . $_SERVER['HTTP_HOST'] . ' ' . date('d-m-Y H:i');

$msg = '<!DOCTYPE html>
<html>
<head>
  <title>Новый отзыв с ' . $_SERVER['HTTP_HOST'] . ' ' . date('d-m-Y H:i') . '</title> 
</head>
<body>
Имя: ' . $_POST['name'] . '<br>
Email: ' . $_POST['email'] . '<br>
Комментарий: ' . $_POST['text'] . '<br>
</body></html>';


require_once ($_SERVER['DOCUMENT_ROOT'] . '/feedback/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();


$mail->AddAddress('info@atomicgarage.ru');
$mail->AddAddress('dasha@eto-design.ru');

//$mail->AddAddress('proviruz@mail.ru');

    $mail->Subject = $subject;
    $mail->SetFrom('admin@atomicgarage.ru');
    $mail->MsgHTML($msg);
    
    $mail->Send();
    
foreach($_POST as $k=>$v) $_POST[$k] = mysql_real_escape_string( $v );

$simpla->db->query("INSERT INTO `__feedback` SET `name`='".$_POST['name']."',`email`='".$_POST['email']."',`text`='".$_POST['text']."', `date`=NOW(), `active`=0, `parent_id`=0 ");
echo mysql_insert_id();
die;
 /*   

$imgs = array();  
if($_POST['images'] > 0){
	$files = scandir($_SERVER['DOCUMENT_ROOT'] . '/feedback/images');
	foreach($files as $file){
		if(strpos($file, $_POST['uid']) === false) continue;
		$imgs[] = $file;
		$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'] . '/feedback/images/'.$file);
	}
}
    
$mail->Send();

//print_r($imgs);

foreach($imgs as $img) @unlink( $_SERVER['DOCUMENT_ROOT'] . '/feedback/images/'.$img );
*/