2016-07-29 8 views
1

Ich habe derzeit Probleme, meine PHP und HTML richtig funktioniert. Wenn ich auf "Senden" klicke, wird eine Fehlerseite angezeigt, die besagt, dass die von mir angeforderte Webseite nicht gefunden werden kann (www.website.com/contact-form-handler.php). HierErstellen von Mailformular in HTML und PHP

ist die PHP und HTML

HTML:

<html> 
<head></head 
<body> 

<div> 
<form action="contact-form-handler.php" method="post" name="contact_form"> 
        <div class="col-md-6 col-sm-6 form-group"> 
         <input name="name" type="text" class="form-control" id="nameInput" placeholder="Name" required> 
         <input name="email" type="email" class="form-control" id="emailInput" placeholder="Email" required> 
         <input name="phone" type="text" class="form-control" id="phoneInput" placeholder="Phone" required> 
         <input name="location" type="text" class="form-control" id="locationInput" placeholder="Event Location" required> 
         <select name="eventType" type="select" class="form-control" id="eventTypeInput"> 
          <option selected>Type of Event</option> 
          <option value="1">Business</option> 
          <option value="2">Party</option> 
          <option value="3">Speech</option> 
         </select> 
         <select name="reference" type="select" class="form-control" id="referenceInput"> 
          <option selected>How did you hear about us?</option> 
          <option value="1">Social Media</option> 
          <option value="2">Word of Mouth</option> 
          <option value="3">Google Search</option> 
         </select>   
        </div> 
        <div class="col-md-6 col-sm-6 form-group"> 
         <textarea name="message" rows="7" class="form-control" id="messageInput" placeholder="Message"></textarea> 
        </div> 
        <div class="col-md-offset-4 col-md-4 col-sm-offset-3 col-sm-6 font3"> 
         <input name="submit" type="submit" class="form-control" id="submit" value="Submit"> 
        </div> 
       </form> 
</div> 
</body> 
</html> 

PHP:

<?php 
$errors = ''; 
$emails = '[email protected]';//<-----Put Your email address here. 
if(empty($_POST['name']) || 
    empty($_POST['email']) || 
    empty($_POST['phone']) || 
    empty($_POST['location']) || 

{ 
    $errors .= "\n Error: Please fill out required fields"; 
} 

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$phone = $_POST['phone']; 
$location = $_POST['location']; 
$eventType = $_POST['eventType']; 
$reference = $_POST['reference']; 
$message = $_POST['message']; 

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address)) 
{ 
    $errors .= "\n Error: Invalid email address"; 
} 

if(empty($errors)) 
{ 
    $to = $emails; 
    $subject = "David Does Stuff Inquiry: $name"; 
    $email_body = "You have received a new message. ". 
    " Here are the details:\n Name: $name \n Email: $email_address \n Phone: $phone \n Location of event: $location \n Type of Event: $eventType \n How did you hear about us: $reference \n Message \n $message"; 

    $headers = "From: $email_address\n"; 
    $headers .= "Reply-To: $emails"; 

    mail($to,$subject,$email_body,$headers); 
    //redirect to the 'thank you' page 
    header('Location: contact-form-thank-you.html'); 

} 
?> 
+0

versuchen, die Seite direkt zugreifen, indem Sie auf yourdomain.com/contact-form-handler.php und sehen, ob es funktioniert – mcky

+0

Nun die Seite ist nicht da, denn der Fehler sagt –

+0

@Dagon, wenn Sie nicht direkt auf die Seite zugreifen können entweder der Seitenname ist falsch oder es ist nicht im selben Verzeichnis – mcky

Antwort

0

Sehen Sie, wenn Sie Ihre PHP-Dateiname "Kontakt-form-handler.php" ist oder vielleicht Sie erhalten den Fehler, weil Ihre PHP-Datei möglicherweise nicht im selben Verzeichnis ist.

-1

Bitte überprüfen Sie Ihre Form

<form action="contact-form-handler.php" method="post" name="contact_form"> 

Ihre Headerort falsch ist, sollte es

//redirect to the 'thank you' page 
header('Location: contact-form-thank-you.php');