F
F
FlapJalc2020-07-15 10:30:54
WordPress
FlapJalc, 2020-07-15 10:30:54

Why is the form handler file not available in Wordpress?

Created the markup for the callback form.

<form class="form" action="<?php bloginfo('template_url') ?>/send.php" method="POST">
  <input type="tel" name="tel" value="Phone">
  <button class="button form__submit">Send</button>
</form>

At the root of the theme, I created a php file that serves as a form handler, accepting POST requests and sending them to an email address.

<?php
require($_SERVER["DOCUMENT_ROOT"]."/wp-load.php");
$to = '[email protected]' // емайл получателя данных из формы
$tema = "Заявка с сайта"; // тема полученного емайла
$message = "Номер телефона: ".$_POST['tel']."";
$headers = 'MIME-Version: 1.0' . "\r\n"; // заголовок соответствует формату плюс символ перевода строки
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; // указывает на тип посылаемого контента
mail($to, $tema, $message, $headers,"-f [email protected]"); //отправляет получателю на емайл значения переменных\
?>

The mediator in all this is a simple AJAX request that does all this without reloading the page.

jQuery(function($){
    $('.form').submit(function(e) {
      e.preventDefault(); 
      var $form = $(this);
      $.ajax({
        type: $form.attr('method'),
        url: $form.attr('action'),
        data: $form.serialize()
        }).done(function() {
          console.log('success');
          $form.trigger( 'reset' );
        }).fail(function() {
          console.log('fail');
        });
    });
  });

So, when sending, the fail method is triggered, and the chrome console displays an error:
POST https://domain.com/wp-content/themes/custom-theme/send.php 500 (Internal Server Error) | jquery.js?ver=1.12.4-wp:4

When accessing a link to a direct link through the browser's address bar, the page responds with an error 500. After submitting the form, in the Network tab of the Dev Tools tool, the send.php file is also indicated with an error 500. Until recently, everything was fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lord_Dantes, 2020-07-17
@Lord_Dantes

500

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question