@SashaPo7

Из-за чего при отправке формы с помощью phpmailer smtp ошибка 409?

При отправке формы на сайте alcoros.com выходит ошибка POST https://alcoros.com/send.php 409 (Conflict) или Failed to load resource: the server responded with a status of 409 (Conflict). Писала на хостин, говорят, что проблема с php кодом, но я не могу понять какая.. Также сказали, что в php коде не определна какая-то переменная, но я не могу понять какая Очень надеюсь, что найдутся умные люди которые подскажут.

Вот мой код:

<form id="form">
   <input name="name" type="text" class="_req" placeholder="Enter your name" autocomplete="on">
   <input name="tel" type="text" class="_req _tel" placeholder="Enter your phone number" pattern="[^A-Za-zА-Яа-яЁё]+$" autocomplete="on">
   <input name="mail" type="email" class="_req _email" placeholder="Enter your email" autocomplete="on">
   <button type="submit">Send</button>
</form>
<div id="message" class="message" role="button" onclick="clouseMassage()">
  <h3>Thank you! <br> We will contact you!</h3>
 </div>


js: 

let message = document.getElementById("message");

function clouseMessage() {
  if (message.style.visibility === "visible") {
    message.style.visibility = "hidden";
    message.style.opacity = "0";
  }
}

"use strict"

document.addEventListener('DOMContentLoaded', function () {
  const form = document.getElementById('form');
  form.addEventListener('submit', formSend);

  async function formSend(e) {
    e.preventDefault();

    let error = formValidate(form);

    let formData = new FormData(form);

    if (error === 0) {
      let response = await fetch("send.php", {
        method: 'POST',
        body: formData
      });
      if (response.ok) {
         console.log('ok');
         form.reset();
         let message = document.getElementById("message");
         message.style.visibility = "visible";
         message.style.opacity = "1";
      }
    } 
  }

  function formValidate(form) {
    let error = 0;
    let formReq = document.querySelectorAll('._req')

    for (let index = 0; index < formReq.length; index++) {
      const input = formReq[index];
      formRemoveError(input);

      if (input.classList.contains('_email')){
        if (emailTest(input)) {
          formAddError(input);
          error++;
        }
      } else if (input.classList.contains('_tel')){
        if (phoneTest(input)) {
          formAddError(input);
          error++;
        }
      } else {
        if (input.value === '') {
          formAddError(input);
          error++;
        }
      }
    }
    return error;
  }
  function formAddError(input) {
    input.classList.add('_error');
  }
  function formRemoveError(input) {
    input.classList.remove('_error');
  }
  function emailTest(input) {
    return !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+$/.test(input.value);
  }
  function phoneTest(input) { 
   return !/^[\d\+][\d\(\)\ -]{4,14}\d$/.test(input.value); 
} 
});


phpmailer:
<?php

require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';
require 'phpmailer/Exception.php';

$name = $_POST['name'];
$email = $_POST['mail'];
$tel = $_POST['tel'];

$mail = new PHPMailer\PHPMailer\PHPMailer();
try {
$mail->isSMTP();
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->Debugoutput = function ($str, $level) {
$GLOBALS['status'][] = $str;
};

$mail->Host = 'smtp.yandex.ru';
$mail->Username = 'a.porsin7';
$mail->Password = 'my password;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('a.porsin7@yandex.ru', 'Alexandra Porsin');

$mail->addAddress('inbox@alcoros.com');

$mail->Subject = "Order from $name";

$emailBody = "Order feedback:";
$emailBody .= "Name: $name
";
$emailBody .= "Mail: $email
";
$emailBody .= "Phone: $tel
";

$mail->Body = $emailBody;
$mail->IsHTML(true); // Set to true if you are sending an HTML-formatted email

if ($mail->send()) {
$result = "success";
} else {
$result = "error";
}
} catch (Exception $e) {
$result = "error";
$status = "Сообщение не было отправлено. Причина ошибки: {$mail->ErrorInfo}";
}

echo json_encode(["result" => $result, "resultfile" => $rfile, "status" => $status]);
?>
  • Вопрос задан
  • 42 просмотра
Решения вопроса 1
@SashaPo7 Автор вопроса
Сама решила, нужно было всего лишь в js написать абсолютный URL к php файлу)
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы