Mam zrobiony formularz kontaktowy, ale nie działa poprawnie. Czy mógłby ktoś zerknąć na kod i poszukać ewentualnej przyczyny?
Contact.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Website Tutorial</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$("html").on("submit","#contact_form",function(e){
e.preventDefault();
$("#send_form_status").html('').hide();
var data=$("#contact_form").serialize();
$.post("contact_form.php",data,function(res){
$("#send_form_status").html(res.msg).show();
if(res.status==1){
$("#contact_form")[0].reset();
}
});
});
});
</script>
</head>
<body>
<section id="contact" class="contact-area" style="margin-top: 50px;">
<div class="container">
<div id="border">
<div id="content">
<h2>Skontaktuj się z nami!</h2>
<form action="contact_form.php" method="post" autocomplete="on" id="contact_form">
<p> <label for="name"> Imię i nazwisko <span class="required">*</span></label> <input type="text" name="name" id="name" required="required"/> </p>
<p> <label for="email"> Adres E-mail <span class="required">*</span></label> <input type="email" name="email" id="email" required="required" placeholder="" /> </p>
<p> <label for="phone"> Telefon kontaktowy </label> <input type="text" name="phone" id="phone"/> </p>
<p> <label for="subject"> Tytuł wiadomości </label> <input type="text" name="subject" id="subject" placeholder="" /> </p>
<p> <label for="message"> Treść wiadomości <span class="required">*</span></label> <textarea required="required" id="message" name="message"></textarea> </p>
<p class="indication"> Wszystkie pola oznaczone <span class="required">*</span> są wymagane</p>
<div class="button"><input type="submit" name="submit" value=" ★ Wyślij wiadomość"/></div>
</form>
<div id="send_form_status"></div>
</div>
</div>
</div>
</section>
</body>
</html>
contact_form.php
<?php
header("content-type: application/json; charset=utf-8");
$name=isset($_POST['name']) ? $_POST['name'] : "";
$email=isset($_POST['email']) ? $_POST['email'] : "";
$phone=isset($_POST['phone']) ? $_POST['phone'] : "";
$subject=isset($_POST['subject']) ? $_POST['subject'] : "";
$message=isset($_POST['message']) ? $_POST['message'] : "";
if($name && $email && $phone && $message){
$headers = "MIME-Version: 1.0\r\nContent-type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: 8bit";
$message_body="Formularz kontaktowy wysłany ze strony GastraCon\n";
$message_body.="Imię i nazwisko: $name\n";
$message_body.="Adres email: $email\n";
$message_body.="Numer telefonu: $phone\n\n";
$message_body.="Tytuł: $subject \n\n";
$message_body.=$message;
if(mail('riven315@gmail.com', $subject, $message_body, $headers)){
$json=array("status"=>1,"msg"=>"<p class='status_ok'>Twój formularz został pomyślnie wysłany.</p>");
}
else{
$json=array("status"=>0,"msg"=>"<p class='status_err'>Wystąpił problem z wysłaniem formularza.</p>");
}
}
else{
$json=array("status"=>0,"msg"=>"<p class='status_err'>Proszę wypełnić wszystkie pola przed wysłaniem.</p>");
}
echo json_encode($json);
exit;
?>