У меня проблема с отправкой электронного письма.Я получаю эту ошибку
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Cannot POST /assets/php/form.php</pre> </body> </html>
Структура моих файлов выглядит следующим образом: dist -asstes --php --- form.php index.html
ВФорма, которую я дал такой путь <form class="fs-13 text-uppercase" id="form" method="POST" action="assets/php/form.php">
Я использую php сервера gulp connect, и это мои taks в файле gulp
// Configure the browserSync task
gulp.task('browserSync', () => {
$.connectPhp.server({}, () => {
browserSync.init({
server: {
baseDir: PATHS.dist,
proxy: '127.0.0.1:8000',
}
});
});
});
// Dev task
gulp.task('dev', ['browserSync', 'vendor', 'assets', 'html', 'sass',
gulp.watch(PATHS.src + '/assets/php/*.php', ['php', browserSync.reload]);
});
Это мой файл js
$('#form').submit(function(event) {
event.preventDefault();
var form = $(this);
var formData = form.serialize();
$.ajax({
type: 'POST',
url: form.attr('action'),
data: formData
}).done(function(response) {
formMessages.text(response);
$('input[name=name]').val('');
$('input[name=email]').val('');
}).fail(function(data) {
if (data.responseText !== '') {
$('.form-status').text(data.responseText);
} else {
$('.form-status').text('ERROR');
}
});
});
и php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = strip_tags(trim($_POST["name"]));
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
if (empty($name) OR empty($email)) {
http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
$recipient = "email@gamil.com";
$subject = "Email";
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n";
$eamil_headers = "From: $name";
if (mail_utf8($recipient, $name, $subject, $email, $email_content, $eamil_headers)) {
http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
} else {
http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
function mail_utf8($recipient, $name, $subject = '(No subject)', $email, $message = '' ) {
$name = "=?UTF-8?B?".base64_encode($name)."?=";
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
$headers = "From: $name <$email>\r\n".
"MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=UTF-8" . "\r\n";
return mail($recipient, $subject, $message, $headers);
}
?>
от
<form id="form" method="POST" action="assets/php/form.php">
<div class="row mb-2">
<div class="col-sm-12 col-md-12">
<div class="form-group">
<input id="first-name" class="form-control text-white" type="text" name="name">
<label for="first-name">your name?*</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-group">
<input id="email" class="form-control text-white" type="email" name="email">
<label for="email">Your email?*</label>
</div>
</div>
<button type="submit" class="btn btn-success float-none float-md-right">Let's work together</button>
</div>
</div>
</form>
Я не знаю, в чем проблема и почему она не отправляет почту