mercredi 9 juin 2021

Form suddenly stops posting data [closed]

My website has been working fine for years and now for some reason it will no longer post data from my form. I'm not sure what's changed in the last week or so. I can only guess that it's something from the java source I'm using has changed, I have tried updating the script src, but I get the same errors. The PHP is returning errors so that looks like it's functioning properly.

The form:

<form class="myForm" method="POST">
  <table>
    <caption class="errorSuccess"></caption>
    <tr>
      <th><label for="staticEmail">&nbsp;&nbsp;To:</label></th>
      <td><input class="staticEmail" placeholder="info@wedgwoodlaundromat.com" readonly></td>
    </tr>
    <tr>
      <th><label for="name"><span class="required">*</span>Name:</label></th>
      <td><input name="name" type="text" id="name" placeholder="John Doe"></td>
    </tr>
    <tr>
      <th><label for="returnEmail">&nbsp;&nbsp;Email Address:</label></th>
      <td><input name="email" type="email" id="returnEmail" placeholder="example@domain.com"></td>
    </tr>
    <tr>
      <td colspan="2"><small class="disclaimer">We'll never share your email with anyone else.</small></td>
    </tr>
    <tr>
      <th><label for="subject"><span class="required">*</span>Subject:</label></th>
      <td><input name="subject" type="text" id="subject" placeholder="Subject of your email"></td>
    </tr>
    <tr>
      <th><label for="emailBody"><span class="required">*</span>Body:</label></th>
      <td><textarea name="body" id="emailBody" rows="5" cols="50"></textarea></td>
    </tr>
    <tr>
      <td class="lft" colspan="2"><small><span class="required">*</span>Required fields.</small></th>
    </tr>
    <tr>
      <td colspan="2"><button class="submit" type="submit">Submit</td>
    </tr>
  </table>
</form>

The JavaScript:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" crossorigin="anonymous"></script>
$(".submit").click(function(e) {
  e.preventDefault();
  $.ajax({
    method: "POST",
    url: "email.php",
    data: $(".myForm").serialize(),
    dataType: "text",
    success: function(data) {
      $(".errorSuccess").html(data);
    },
    error: function(response) {
      console.log(response)
    },
  });
});

The PHP:

<?php

$missingInfo = "";
$errorMessage = "";
$email = "";
$success = "";
$emailError = "";
$to = "";
$message = "";
$header = "";
$subject = "";
$headerName = "";
$sent = mail($to, $subject, $message, $header);
$emailpass = "";

if ($_POST) {
    if (!$_POST['name']) {
        $missingInfo .= '<br>Name';
    }

    if (!$_POST['subject']) {
        $missingInfo .= '<br>Subject';
    }

    if (!$_POST['body']) {
        $missingInfo .= '<br>Body';
    }

    if ($_POST['email']) {
        if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $email =
                'This customer would like a return email: ' . $_POST["email"];
        } else {
            $emailError = '<div id="error">Please correct email</div>';
        }
    }

    if ($missingInfo) {
        $errorMessage =
            '<div id="error"><strong>The following items are missing:</strong>' .
            $missingInfo .
            '</div>';
    } elseif (!$emailError) {
        $to = "diablogatollc@gmail.com";

        $headerName = str_replace(' ', '', $_POST['name']);

        $subject = $_POST['subject'];

        $txt = $_POST['body'];

        $header =
            "From: " .
            $_POST["name"] .
            "<" .
            $headerName .
            "@wedgwoodlaundromat.com>\n";

        $message =
            '' .
            $txt .
            '
            
            ' .
            $_POST["name"] .
            '

            ' .
            $email .
            '';

        mail($to, $subject, $message, $header);
    }

    if ($sent === false && !$errorMessage && !$emailError) {
        $success = '<div id="success">Success! Thank you for your time!</div>';
    } elseif (!$errorMessage && !$emailError) {
        $emailError =
            '<div id="error">Email could not be sent, please try again later.</div>';
    }
}

if ($success || $errorMessage || $emailError) {
    echo $success, $errorMessage, $emailError;
}

?>



Aucun commentaire:

Enregistrer un commentaire