0

这是我的 php 代码,它获取数据,但似乎只是死了,它确实回显了我不能的错误代码;似乎找不到它在某一时刻工作的原因。这会从 html 表单中提取数据,如果需要,我可以加载它。

感谢您的关注。

    <?php
       if(isset($_POST['email'])) {

          // EDIT THE 2 LINES BELOW AS REQUIRED
          $email_to = "blahblah@gmail.com";
          $email_subject = "Runner Registration";


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted.  ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

        $gender = 'unchecked';
        $size = 'unchecked';

    if (isset($_POST['gender'])) {
        $selected_radio = $_POST['gender'];
            if ($selected_radio == 'male') {
                $gender = 'Male';
            }
            else if ($selected_radio == 'female') {
                $gender = 'Female';
            }
    }



    if (isset($_POST['size'])) {
        $selected_radio = $_POST['size'];
            if ($selected_radio == 'small') {
                $size = 'Small';
            }
            else if ($selected_radio == 'medium') {
                $size = 'Medium';
            }
            else if ($selected_radio == 'large') {
                $size = 'Large';
            }
            else if ($selected_radio == 'xlarge') {
                $size = 'X-Large';
            }
            else 
                $size = 'XX-Large';

    }



    // validation expected data exists
    if(!isset($_POST['last-name']) ||
        !isset($_POST['first-name']) ||
        !isset($_POST['initial']) ||
        !isset($_POST['address']) ||
        !isset($_POST['city']) ||
        !isset($_POST['state']) ||
        !isset($_POST['zip']) ||
        !isset($_POST['phone']) ||
        !isset($_POST['email']) ||
        !isset($_POST['econtact']) ||
        !isset($_POST['ephone']) ||
        !isset($_POST['age'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $first_name = $_POST['first-name']; // required
    $last_name = $_POST['last-name']; // required
    $initial = $_POST['initial']; // required
    $address = $_POST['address']; // required
    $city = $_POST['city']; // required
    $state = $_POST['state']; // required
    $zip = $_POST['zip']; // required
    $phone = $_POST['phone']; // required
    $email = $_POST['email']; // required
    $econtact = $_POST['econtact']; // required
    $ephone = $_POST['ephone']; // required
    $age = $_POST['age']; // required
    $size = $_POST['size']; // required


    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$email)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }

  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Initial: ".clean_string($initial)."\n";
    $email_message .= "Address: ".clean_string($address)."\n";
    $email_message .= "City: ".clean_string($city)."\n";
    $email_message .= "State: ".clean_string($state)."\n";
    $email_message .= "Zip: ".clean_string($zip)."\n";
    $email_message .= "Phone: ".clean_string($phone)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "Emergency Contact: ".clean_string($econtact)."\n";
    $email_message .= "Emergency Phone: ".clean_string($ephone)."\n";
    $email_message .= "Gender: ".clean_string($gender)."\n";
    $email_message .= "Age: ".clean_string($age)."\n";
    $email_message .= "Shirt Size: ".clean_string($size)."\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>


Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>
4

0 回答 0