2016-10-05 4 views
-2

私のサイトに連絡先を追加しようとしましたが、うまくいかないようです...フォームを送信すると、空白のページ(URLに入力された詳細情報)が表示されます。htmlとphpを参照してください以下のフォーム。PHPのコンタクトフォームは動作しませんか?

HTML

<form action="contact.php">     
    <input type="text" placeholder="Full Name" value="" name="name" /> 
    <br> <br> 
    <select name="property"> 
     <option value="Commercial">Commercial</option> 
     <option value="Residential">Residential</option> 
    </select> 
    <br> <br> 
    <select name="work"> 
     <option value="Electrical">Electrical</option> 
     <option value="Gas">Gas</option> 
     <option value="Carpentry">Carpentry</option> 
     <option value="Painting">Painting & decorating</option> 
     <option value="Building">Building</option> 
     <option value="Flooring">Floor fitting</option> 
    </select> 
    <br> <br> 
    <input type="text" placeholder="Email Address" value="" name="email" /> 
    <br> <br> 
    <input type="submit" value="Submit"> 
</form> 

PHP

<?php 

if(isset($_POST['email'])) { 
    // EDIT THE 2 LINES BELOW AS REQUIRED 
    $email_to = "[email protected]"; 
    $email_subject = "CONTACT FORM APPLICATION"; 

    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(); 
    } 

    // validation expected data exists 
    if(!isset($_POST['name']) || 
     !isset($_POST['email']) || 
     !isset($_POST['property']) || 
     !isset($_POST['work'])) 
     $name = $_POST['name']; // required 
     $email = $_POST['email']; // required 
     $property = $_POST['property']; // required 
     $work = $_POST['work']; // required 

    $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 .= "Name: ".clean_string($name)."\n"; 
    $email_message .= "email: ".clean_string($email)."\n"; 
    $email_message .= "property: ".clean_string($property)."\n"; 
    $email_message .= "work: ".clean_string($work)."\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); 
?> 

<!-- include your own success html here --> 
<center> 
    <br><br><br> 
Thank you for your enquiry, we will be in touch shortly<br><br> <img src="_include/img/smile.png"><br><br>You may now close you browser or go back to our home page by clicking <a href="index.html">here</a> 
</center> 

<?php } ?> 

私が間違って何をしているのですか?誰もがエラーを見ることができるようにソリューションを投稿できますか?

答えて

0
<form action="contact.php"> 

デフォルトはGETですので、あなたが必要です:

<form action="contact.php" method="post"> 
関連する問題