Answer the question
In order to leave comments, you need to log in
AJAX + PHP + JS form is not being sent, why is the php script not being executed?
I need to send a feedback form from the landing page to the mail, but something went wrong and the form is not processed by php, in the console I get "POST localhost:3000/save.php 404 (Not Found)"
Help, what am I doing wrong?
UPD: When I go to localhost:3000/save.php, the save.php file is simply downloaded... That is, it is there, but why is it not processed through it?!
HTML
<form class="b-form" id="main-form">
<div class="b-form__row">
<label for="name" class="b-label">Ваше имя</label>
<input id="name" type="text" name="name" class="b-input b-form__input" placeholder="Ваше имя" />
</div>
<div class="b-form__row">
<label for="email" class="b-label">Электронная почта</label>
<input id="email" type="email" name="email" class="b-input b-form__input" placeholder="Email" required/>
<div class="b-form__help">Обязательно для заполнения</div>
</div>
<div class="b-form__row">
<label for="phone" class="b-label">Телефон <span class="b-aster">*</span></label>
<input id="phone" type="tel" name="phone" class="b-input b-form__input b-phone__mask" placeholder="Телефон" required/>
<div class="b-form__help">Обязательно для заполнения</div>
</div>
<div class="b-form__row">
<input type="submit" class="b-button b-button_blue" value="Отправить" />
</div>
</form>
$(document)
.on('submit', '#main-form', e => {
e.preventDefault();
let form_data = $(this).serialize();
$.ajax({
type: "POST",
url: "/save.php",
data: form_data,
success: function() {
alert("Ваше сообщение отправлено!");
}
});
});
<?php
$recepient = "[email protected]";
$sitename = "Бюро Сервис";
$name = trim($_POST["name"]);
$phone = trim($_POST["phone"]);
$email = trim($_POST["email"]);
$message = "Имя: $name \nТелефон: $phone \nEmail: $email";
$pagetitle = "Новая заявка с сайта \"$sitename\"";
mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $recepient");
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question