Why email sending doesn't work?
-
I broke my whole head, I do not understand what the error is and what is wrong, I upload it to the server, it gives an error, what is the matter is not clear, who is not lazy, why does it not work?
<form action="#" id="form" method="POST" > <div class="form__img"> <img src="images/delivery/щит.png" alt=""> </div> <div class="form__title">Оставьте заявку</div> <div class="form__text">Консультант свяжется <br> с вами в течении 12 часов</div> <div class="form__group"> <input type="text" class="form__input phone _req " name="phone" required id="number" placeholder=" "> <label for="number" class="form__label">Ваш телефон</label> </div> <div class="form__group"> <input type="text" class="form__input _req" name="name" required id="name" placeholder=" "> <label for="name" class="form__label">Ваше имя</label> </div> <button type="submit" class="btn__link color-1 btn">Отправить заявку</button> </form>
document.addEventListener('DOMContentLoaded', function () { const form = document.getElementById('form'); form.addEventListener('submit', formSend); async function formSend(e) { e.preventDefault(); let formData = new FormData(form); form.classList.add('_sending'); let response = await fetch ('send.php', { method: 'POST', body: formData }); if (response.ok) { let result = await response.json(); alert(result.message); form.reset(); form.classList.remove('_sending'); } else { alert("Ошибка") form.classList.remove('_sending'); } } });
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\SMTP; require 'modules/PHPMailer/src/Exception.php'; require 'modules/PHPMailer/src/PHPMailer.php'; require 'modules/PHPMailer/src/SMTP.php'; $mail = new PHPMailer(true); $mail->IsSMTP(); $mail->Host = 'Скрыл'; $mail->SMTPAuth = true; $mail->Username = 'Скрыл'; $mail->Password = 'Скрыл'; $mail->SMTPSecure = 'ssl'; $mail->Port = 465; $mail->CharSet = 'UTF-8'; $mail->setLanguage('ru', 'modules/phpmailer/language/'); $mail->IsHTML(true); $mail->setFrom('Скрыл', 'Скрыл'); $mail->addAddress('Скрыл', 'Скрыл'); $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>phone:</strong> '.$_POST['phone'].'</p>'; } $mail->Body = $body; if (!$mail->send()) { $message = 'Ошибка'; } else { $message = 'Данные отправлены!'; } $response = ['message' => $message]; header('Content-type: application/json'); echo json_encode($response);
If you help me, you are godJavaScript Anonymous, Apr 6, 2020 -
what error occurs?Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!