简体   繁体   中英

Report Form not submitting (php, html)

I'm creating a small website and I have a one question report form. The problem is the email isn't sending. I'm not sure what I did wrong. I think there might be something wrong with the php, or maybe the html, I'm not the best with forms. Thanks for the help!

Here's my code:

html

 <h2 style="font-size:30px;"><i class="fa fa-exclamation-circle"></i> Report Game</h2>
    </div>
    <hr class="descriptionline3">
    <div class="modal-body3">

        <form action="report.php" id="errorform" onsubmit = "return validate();">

      <p style="color:#363636;text-align:left;padding-left:10px;">What seems to be the problem?</p>
      <input type="text" class="forminputproblem" id="name" placeholder="Write the problem here..." style="height:20px;font-size:14px;border-radius:6px;display:inline-block;border:1px solid #ccc;padding: 12px 20px;
">

        <div style="height:10px;"></div>   

        <div style="color:red;" id="error_message"></div>

        <div style="color:green;" id="success_message"></div>

        <div style="height:10px;"></div>   

    <input name="sumbit" type="submit" value="SEND REPORT">
</form>

php


<?php

    if (isset($_POST['submit'])) {
        $name = $_POST['name'];

    $mailTo = "contact@rileysunblockedgames.com";
    $headers = "Report Form Message";
    $txt = "You have received a report form message: ".$name.".\n\n";


mail($mailTo, $txt, $headers);
header("Location: /games.html?reportsent");

    }

?>

javascript

function validate(){
  var name = document.getElementById("name").value;
  var error_message = document.getElementById("error_message");
  
  error_message.style.padding = "10px";
  
  var text;

  if(name.length < 10){
    text = "&#10006; Report message has to be at least 10 characters!";
    error_message.innerHTML = text;
    text = "";
    success_message.innerHTML = text;
    return false;
  }

  text = "";
    error_message.innerHTML = text;
text = "&#10004; Report has been submitted! We will get back to you as soon as possible.";
    success_message.innerHTML = text;
    return true;
}

Thanks!

By checking out the mail function's parameters...

mail($to, $subject, $message, $headers);

It seems like the problem is that your variables are a bit mixed up. Also, "header" doesn't refer to the subject: email headers contain info and have their own syntax. Try this code:

<?php

    if (isset($_POST['submit'])) {
        $name = $_POST['name'];

    $mailTo = "contact@rileysunblockedgames.com";
    $subject = "Report Form Message";
    $headers = 'From: noreply@rileysunblockedgames.com' . "\r\n" .
    'Reply-To: noreply@rileysunblockedgames.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    $txt = "You have received a report form message: ".$name.".\n\n";

    mail($mailTo, $subject, $txt, $headers);
    header("Location: /games.html?reportsent");

    }

?>

Also, on your input, you have to define the "name" attribute for it to work properly:

<input type="text" class="forminputproblem" name="name" id="name" placeholder="Write the problem here..." style="height:20px;font-size:14px;border-radius:6px;display:inline-block;border:1px solid #ccc;padding: 12px 20px;">

Also also (and funny enough this is the biggest barrier in your way right now), there is a typo in your submit button's name, so your PHP code will never run:

<input name="submit" type="submit" value="SEND REPORT">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM