2016-10-05 5 views
-2

Ich habe versucht, einen Kontakt von meiner Seite hinzufügen, aber es scheint nicht zu funktionieren ... beim Absenden des Formulars dauert es mich nur auf eine leere Seite (mit den in der URL eingegebenen Details) Bitte sehen Sie die HTML-und PHP Formular unten.PHP-Kontaktformular funktioniert nicht?

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 } ?> 

Was mache ich falsch? Kann jemand eine Lösung posten, damit ich die Fehler sehen kann?

Antwort

0
<form action="contact.php"> 

der Standard ist GET, so benötigen Sie:

<form action="contact.php" method="post"> 
Verwandte Themen