Elena2021-03-19 19:29:54
Elena, 2021-03-19 19:29:54

405 method not allowed because of what?

There were no particular problems, I needed a form with sending data to the mail and problems immediately appeared.
Here is my code, what is wrong?

const formTest = () => fetch('form.php', {
  method: 'POST',
  body: JSON.stringify({
    email: '[email protected]',
    text: 'test'


use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';

$mail->setFrom('[email protected]', 'GGG');
$mail->addAddress('[email protected]');
$mail->Subject = 'TTT';

$body = '<h1>bffbvdvbhbfv</h1>';

$body = $_POST['email'];
$body = $_POST['text'];

$mail->Body = $body;
if(!$mail->send()) {
  $message = 'ooooo';
} else {
  $message = 'qqqqq';
$response = ['message' => $message];
header('Content-type: application/json');
echo json_encode($response);


Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question