Код: Выделить всё
<?php
session_start();
if(isset($_POST["button"])){
$name = filter_var(trim($_POST['name']), FILTER_SANITIZE_STRING);
$email = filter_var(trim($_POST['email']), FILTER_SANITIZE_STRING);
$comment = htmlspecialchars($_POST["comment"]);
$to = "egorkaratunov2003@gmail.com";
$_SESSION['name'] = $name;
$_SESSION['email'] = $email;
$_SESSION['comment'] = $comment;
$error = false;
if($name == ""){
$error = true;
$error_name = "Please enter name!";
}
if ($email == "" || !preg_match("/@/", $email)){
$error = true;
$error_email = "Please enter email! Email should be contain @";
}
if ($comment == "") {
$error = true;
$error_comment = "Please enter comment!";
}
if(!$error){
$headers = "From:$email\r\n Reply-to:$email\r\n Content-type:text/plain; charset=utf-8";
mail($to, " ", $comment, $headers);
$mysql = new mysqli('localhost','имя_admin',Пароль акка','users');
$mysql ->query("INSERT INTO `users` (`Name`, `Email`, `Message`) VALUES('$name','$email','$comment')");
$mysql ->close();
header('Location: index.php?send=1');
session_destroy();
exit();
}
}
?>