2016-11-30 10 views
0

Ich frage mich, wie man es macht, wo ich meine Absenden-Taste klicke und die URL nicht ändert. Gerade jetzt, wenn ich es anklicke, schickt es mir einfach die Aktionsseite.Redirect-Seite nach dem Klicken auf Senden

Der PHP-Code ist

<?php 
 
// Check for empty fields 
 
if(empty($_POST['name']) \t \t || 
 
    empty($_POST['email']) \t \t || 
 
    empty($_POST['message']) \t || 
 
    !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) 
 
    { 
 
\t echo "No arguments Provided!"; 
 
\t return false; 
 
    } 
 
\t 
 
$name = strip_tags(htmlspecialchars($_POST['name'])); 
 
$email_address = strip_tags(htmlspecialchars($_POST['email'])); 
 
$message = strip_tags(htmlspecialchars($_POST['message'])); 
 
\t 
 
// Create the email and send the message 
 
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to. 
 
$email_subject = "Website Contact Form: $name"; 
 
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nMessage:\n$message"; 
 
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected] 
 
$headers .= "Reply-To: $email_address"; \t 
 
mail($to,$email_subject,$email_body,$headers); 
 
return true; \t \t 
 
?>

Ich Wenn jemand fragen kann mich dazu beitragen, so dass es auf der Seite Umleiten statt bleibt.

+1

Versuchen umleiten zurück mit 'Header:;' nach dem Fertig Mailing ('Location' $ _SERVER [ 'HTTP_REFERER'].). –

+0

wo würde ich das setzen, ich habe das Ende des Codes versucht und es hat nicht funktioniert – wot

+0

macht mir nichts aus. funktioniert :). ty – wot

Antwort

1

Sie sollten die gleichen Seite wie die Aktionsseite verwenden wie:

<form action = 'samepage.php'> 
    <input type='text' name = 'name'> 
    <input type='text' name = 'email'> 
    <input type='text' name = 'message'> 
    <button type="submit">Submit</button> 
</form> 
<?php 
// Check for empty fields 
if(empty($_POST['name']) 
... 
... 
?> 
Verwandte Themen