使用HTML5和php制作一个简单的联系人框可以正常工作

I have a question about making these two pieces of code work together. I have gone through several days struggling to find why this produces a blank page that directs to contact.php instead of sending the email with the data. Simply The Name, Business Name and Email. I am not a php programmer and would appreciate the help, or perhaps if someone could steer me in the right direction.

HTML5 sample

<form method="post" action="contact.php">
    <fieldset>
        <label for="alerts-name">Your Name</label> 
        <input type="text" name="name" id="alerts-name"  class="input" maxlength="30">
        </fieldset>
        <fieldset>
          <label for="alerts-business">Business Name</label> 
          <input type="text" name="business" id="alerts-business" class="input" maxlength="50">
        </fieldset>
        <fieldset>
          <label for="alerts-email">Your email</label> 
          <input type="text" name="email" id="alerts-email" class="input" maxlength="30">
        </fieldset>
        <label>*What is 2+2? (Anti-spam)</label><br />
        <input name="human" placeholder="Type Here">
        <fieldset>
        <br />
        <fieldset>
          <input type="submit" value="submit">
        </fieldset>
      </form>

Below is the php code I am using.

<?php
  $name = $_POST['name'];
  $business = $_POST['business'];
  $email = $_POST['email'];
  $from = 'From: The Web Site';
  $to = 'myemail@site.com';
  $subject = 'Hello';
  $human = $_POST['human'];
  $body = "From: $name
 business: $business
 email:
 $email";

  if ($_POST['submit'] && $human == '4') {
  if (mail ($to, $name, $business, $email) ) {
  echo '<p>Your message has been sent!</p>';

  } else {
  echo '<p>Something went wrong, go back and try again!</p>';
  }
  } else if ($_POST['submit'] && $human != '4') {
  echo '<p>You answered the anti-spam question incorrectly!</p>';
  }

  ?>

Firstly your 'from' header is incorrectly formatted - this should either be:

'From: The Website <the@website.com>'; or should simply be left out as this is an optional paramater to the mail() function.

You also then pass four parameters to the mail() function - to, name, business and email. The appropriate paramaters are listed with the PHP documentation, they are:

mail (string $to, string $subject, string $message[, string $additional_headers[, string $additional_parameters]]);

In this sense your function should read something more like:

mail($to, $subject, $email);

tl;dr:

You use $business as part of your mail function where you should really be including the message, meaning your email body is being interpreted as the email headers and is totally incorrectly formatted.

Could you just confirm that this is the PHP code you have in the "contact.php" file? Or is all of this in the same file?

You're not using the $subject variable in your PHP. And your "human" element should probably have a type="text" (or type="number") attribute in the HTML too.

I've had a lot more success with the PHPMailer extension when performing tasks with email, and you can get the most recent version from github. There's a good usage example over there to get you started.

Also, as an aside, as you're coding in HTML5, you can safely use the new "email" type of input which has some nice built-in validation:

 <input type="email" name="email" id="alerts-email" class="input" maxlength="30">