S
S
satioidou2se2019-06-22 06:24:56
PHP
satioidou2se, 2019-06-22 06:24:56

I'm trying to make a feedback form using ajax + PHPMailer. Data is not sent. What to do?

When trying to send data in the browser console, the message "XHR failed loading: POST site/handler.php" appears
when sending something like

spoiler

<?php
echo $_POST['name'];
?>


data is being output easily. those. from the front, everything is ok and everything is sent.
the handler.php file itself looks like this and the problem is most likely in it. I ask for help!
spoiler

<?php
// Файлы phpmailer
require 'mailer/PHPMailer/src/PHPMailer.php';
require 'mailer/PHPMailer/src/SMTP.php';
require 'mailer/PHPMailer/src/Exception.php';
// Переменные, которые отправляет пользователь
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$mail = new PHPMailer\PHPMailer\PHPMailer();
try {
$msg = «ok»;
$mail->isSMTP();
$mail->CharSet = «UTF-8»;
$mail->SMTPAuth = true;
// Настройки вашей почты
$mail->Host = 'smtp.gmail.com'; // SMTP сервера GMAIL
$mail->Username = 'логин@gmail.com'; // Логин на почте
$mail->Password = 'пароль'; // Пароль на почте
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('логин@gmail.com', 'Site'); // Адрес самой почты и имя отправителя
// Получатель письма
$mail->addAddress('логин@mail.ru'); 
// -----------------------
// Само письмо
// -----------------------
$mail->isHTML(true);

$mail->Subject = 'Заголовок письма';
$mail->Body = "<b>Имя:</b> $name <br>
<b>Почта:</b> $email<br><br>
<b>Сообщение:</b><br>$phone";
// Проверяем отравленность сообщения
if ($mail->send()) {
echo "$msg";
} else {
echo «Сообщение не было отправлено.Неверно указаны настройки вашей почты»;
}
} catch (Exception $e) {
echo «Сообщение не было отправлено. Причина ошибки: {$mail->ErrorInfo}»;
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
satioidou2se, 2019-06-22
@satioidou2se

problem solved. the error was in the validator (a separate file that did not pass data as it should)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question