Hi,
I know this question was already asked - I’ve read the tips there but my contact form just dont want to work and I cant find the error.
The redirection with header doesnt work, all other ponts works except of this one.
I know that bevor header() no output should be done - I checked that there is no space or free line bevor <?php
Probably somebody can help me:confused:
here is the code for contact form
<?php
include ("valid_form.php");
if(isset($_POST['submit'])){
$name=check_input($_POST['name']);
$email=check_input($_POST['email']);
$anfrage=check_input($_POST['anf']);
$error_msg="";
//Ueberpruefung, ob was eingegeben ist im Feld name
if(strlen($name)<3)
{
$error_msg="<li >Enter your name</li>";
}
//Ueberpruefung der validen eamil adresse
if (!preg_match("/([\\w\\-]+\\@[\\w\\-]+\\.[\\w\\-]+)/", $email))
{
$error_msg.="<li>Enter your e-mail adress</li>";
}
//Ueberpruefung ob bei der Anfrage etwas eingegeben wurde
if(strlen($anfrage)<3){
$error_msg.="<li>Enter your Question</li>";
}
//Ausgabe der Fehlermeldung oder Versand der email
if(strlen($error_msg)>0)
{
//Eines der Felder wurde nicht korrekt ausgefuellt
echo "<p>your question wasnot sent because<p><ul>";
echo $error_msg;
echo "</ul><p>Click to<a href=\\"javascript:history.back(1)\\">back</a> and fill everything</p><br/>";
}
else{
//Alle Felder ausgefuellt - eMail generieren
$recipient="test@test.at";
$subject="A Question from your website";
$header="From: " . $email . "\\r\
";
$mail_body ="The Form was filled on " . date("d.m.Y") . " at " . date("H:i") . "h.\
";
$mail_body.="Following inputs were entered:\
\
";
$mail_body.="Name: " . $name . "\
";
$mail_body.="eMail: " . $email . "\
\
";
$mail_body.="Question: " . $anfrage . "\
\
";
$mail_body.="\
\
---- End of automatically generated mail ----";
}
mail($recipient,$subject,$mail_body,$header);
header('Location: test.html');
exit;
}else{
header('Location: contact.html');
exit;
}
?>
and here is the code for validation - validation works fine
<?php
//Funktionen
//print "Valiedierungsfunktionen eingefuegt OK";
//CHECK_INPUT
function check_input($testString)
{
$testString = trim($testString);
$testString = stripslashes($testString);
$testString = htmlspecialchars($testString);
return $testString;
}
?>
Please give me a tip what can I also check or where can be the error
Thanks