Gurgen Gurgen - 6 months ago 9x
PHP Question

Failed to write a feedback form PHP

I need your help. I have a feedback form, which sends an email to a specified mailbox.
This is how my form looks like:

<form method=post name="feedback">
<div align="center">
<input class="textarea1" type="text" name="name" placeholder="Name" autocomplete="off">
<input class="textarea1" type="text" name="email" placeholder="Email" autocomplete="off">
<input class="textarea1" type="text" name="title" placeholder="Subject" autocomplete="off">
<textarea class="textarea" rows="10" name="mess" placeholder="Message" autocomplete="off"></textarea><br />
<input class="submit" type="submit" value="Send" name="submit"></div>
<img id="load" src="load.gif" style="display: none;" />
<div id="answer"></div>

This is how my script looks like in head of the html file:

<script type="text/javascript" src="jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#feedback").submit(function(event) {
url: "feedback_lib.php",
beforeSend: function() {
type: "post",
data: $("#feedback").serialize(),
success: function(answer) {
}).done(function() {

And this is how my feedback_lib.php look like:


$email = $_POST["email"];
$mess = $_POST["mess"];
$title = $_POST["title"];
$name = $_POST["name"];
$result = 0;
define(EMAIL_TO, "");

if ((strlen($email) < 5) or (strlen($message) < 10)) $result = 1; // длина сообщения
else {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$subject = "Письмо с Вашего сайта http://".$_SERVER["HTTP_HOST"]."/";
$header = "From <".$email.">\r\nContent-type: text/plain; charset=utf-8\r\n";
mail(EMAIL_TO, $subject, $mess, $title, $name);
$result = 3; //письмо отправлено
else $result = 2; // неправильный email
echo getAnswer($result);

function getAnswer($result = 0) {
switch ($result) {
case 0: $answer = "";
case 1: $answer = "<p style='color: red;'>Հաղորդագրության նվազագույն երկարություն 10 նիշ, իսկ email-ինը` 5:</p>";
case 2: $answer = "<p style='color: red;'>Սխալ email:</p>";
case 3: $answer = "<p style='color: green;'>Հաղորդագրությունն ուղարկված է</p>";
return $answer;


And my question is: why it doesn't work?
Where's my fault?
Thanks for answers.


Use feedback id in the form.

<form method=post name="feedback" id="feedback">