Что дописать в php, чтобы вывести поп-ап message?
async function form_submit(e) {
let btn = e.target;
let form = btn.closest('form');
let error = form_validate(form);
if (error == 0) {
let formAction = form.getAttribute('action') ? form.getAttribute('action').trim() : '#';
let formMethod = form.getAttribute('method') ? form.getAttribute('method').trim() : 'GET';
const message = form.getAttribute('data-message');
const ajax = form.getAttribute('data-ajax');
//SendForm
if (ajax) {
e.preventDefault();
let formData = new FormData(form);
form.classList.add('_sending');
let response = await fetch(formAction, {
method: formMethod,
body: formData
});
if (response.ok) {
let result = await response.json();
form.classList.remove('_sending');
if (message) {
popup_open(message + '-message');
}
form_clean(form);
} else {
alert("Ошибка");
form.classList.remove('_sending');
}
}
// If test
if (form.hasAttribute('data-test')) {
e.preventDefault();
if (message) {
popup_open(message + '-message');
}
form_clean(form);
}
} else {
let form_error = form.querySelectorAll('._error');
if (form_error && form.classList.contains('_goto-error')) {
_goto(form_error[0], 1000, 50);
}
e.preventDefault();
}
}
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$mail->setLanguage('ru', 'phpmailer/language/');
$mail->IsHTML(true);
//От кого письмо
$mail->setFrom('user@info.com');
//Кому отправить
$mail->addAddress('user@info.com');
//Тема письма
$mail->Subject = 'Тема';
//Тело письма
$body = '<h1>Тело письма</h1>';
if(trim(!empty($_POST['name']))){
$body.='<p><strong>Имя:</strong> '.$_POST['name'].'</p>';
}
if(trim(!empty($_POST['email']))){
$body.='<p><strong>E-mail:</strong> '.$_POST['email'].'</p>';
}
if(trim(!empty($_POST['message']))){
$body.='<p><strong>Сообщение:</strong> '.$_POST['message'].'</p>';
}
$mail->Body = $body;
$response = ['message' => $message];
header('Content-type: application/json');
echo json_encode($response);
?>