0

送信後にフォームをクリアしようとしています。何が欠けているのかわかりません。以下にPHPコードを添付します。お問い合わせフォームなどを PHP を使用してコーディングするのはこれが初めてなので、ご容赦ください。よろしくお願いします!

申し訳ありませんが、コードを添付したと思いました。

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

    // EMAIL AND SUBJECT
    $email_to = "##@##.com";

    $email_subject = "New form submission";


    function died($error) {
        // your error code can go here
        echo "<span style='color: red;' /><center> We're sorry, but there's errors found with the form you submitted.<br /><br /></center></span>";
        echo $error."<br /><br />";
        echo '<span style="color: red;" /><center>Please go back and fix these errors.<br /><br /></center></span>';
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['message'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.</center></span>');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $message = $_POST['message']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= '<span style="color: red;" /><center>The Email Address you entered does not appear to be valid.<br /></center></span>';
  }
    $string_exp = "/^[0-9.-]+$/";
  if(!preg_match($string_exp,$telephone) > 10) {
    $error_message .= '<span style="color: red;" /><center>The Telephone number you entered does not appear to be valid.<br /></center></span>';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= '<span style="color: red;" /><center>The First Name you entered does not appear to be valid.<br /></center></span>';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= '<span style="color: red;" /><center>The Last Name you entered does not appear to be valid.<br /></center></span>';
  }
  if(strlen($message) < 10) {
    $error_message .= '<span style="color: red;" /><center>The Message you typed seems to be too short, add more words, please.</center></span><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 .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Message: ".clean_string($message)."\n";


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

<!-- The success html below -->
<span style="color: green;"><center>Thank you for contacting us. We will be in touch with you very soon.</center></span>

<?php
}
die();
?>
4

2 に答える 2