2016-03-24 4 views
1

Hier ist mein HTML-Code mit meinem Formular. Diese Datei wird interested.htmlKann meine PHP-Seite nicht zu meiner HTML-Dankeseite umleiten. Was mache ich falsch?

namens

<h1 id="title5">Write Me</h1> 
 
    <p align="center" style="font-size:20px">If you would like to get in touch with me, please do!</p> 
 
    <form method="post" action="contact.php"> 
 
     <fieldset> 
 
     <input name="name" type="text" placeholder="Full Name"> 
 
     <input name="email" type="email" placeholder="Email Address"> 
 
     <textarea name="msg" placeholder="Your message..."></textarea> 
 
     </fieldset> 
 
     <input type="submit" class="Send"> 
 
    </form>

Das ist mein PHP-Code. Nachdem das Formular ausgefüllt ist, möchte ich meine Dankeseite (sent.html) anstelle dieser Seite zeigen. Diese Datei wird contact.php

namens

<?php 
 
//redirect to thank you page 
 
//if information is not entered properly send to error page 
 
//submit an confirmation email to me 
 

 
    $name = $_POST["name"]; 
 
    $email = $_POST["email"]; 
 
    $msg = $_POST["msg"]; 
 

 
    echo "<pre>"; 
 
    $email_body = ""; 
 
    $email_body .= "Name " . $name . "\n"; 
 
    $email_body .= "Email " . $email . "\n"; 
 
    $email_body .= "Message " . $msg . "\n"; 
 
    echo $email_body; 
 
    echo "</pre>"; 
 

 
    header("location:sent.html"); 
 

 
?>

Bitte helfen Sie, und lassen Sie es mich wissen, wenn ich nicht meine Frage gut genug, um erklären oder, wenn mehr Informationen benötigt werden.

Vielen Dank im Voraus!

Antwort

1

Die Header-Anweisung muss aufgerufen werden, bevor ein Inhalt zurückgegeben wird. Aber Sie schreiben echo vor header.

+0

Ich bin ein Idiot. Danke für die schnelle Antwort funktionierte perfekt. :) –

0

Versuchen

<?php 
ob_start(); 
//redirect to thank you page 
//if information is not entered properly send to error page 
//submit an confirmation email to me 

    $name = $_POST["name"]; 
    $email = $_POST["email"]; 
    $msg = $_POST["msg"]; 

    echo "<pre>"; 
    $email_body = ""; 
    $email_body .= "Name " . $name . "\n"; 
    $email_body .= "Email " . $email . "\n"; 
    $email_body .= "Message " . $msg . "\n"; 
    echo $email_body; 
    echo "</pre>"; 

    header("location:sent.html"); 

?> 
+0

funktioniert in lokalen Host, aber es funktioniert nicht auf meinem github.io –

+0

ist es github Seite? Github unterstützt nicht PHP –

Verwandte Themen