My Code was working before, now it suddenly stopped working, can someone tell me why?
I can't see the error log as they are not written down and its empty somehow
Im requesting all the fields from the html form and on submit it should send the mail.
Is there maybe an error with the headers section? I'm really not sure as i can't see the logs.
<?php
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $message = $category = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name wird benötigt";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Nur Buchstaben und Leerzeichen sind erlaubt.";
}
}
}
if (empty($_POST["email"])) {
$emailErr = "Email wird benötigt";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Ungültiges E-Mail Format";
}
}
if (empty($_POST["category"])) {
$category = "";
} else {
$category = test_input($_POST["category"]);
}
if (empty($_POST["message"])) {
$message = "";
} else {
$message = test_input($_POST["message"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$fullmessage = $category." \r\n ".$message;
$to="support@gerber-web.ch";
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=utf-8";
$headers[] = "From: {$email}";
$headers[] = "Reply-To: {$email}";
$headers[] = "Subject: {$name}";
$headers[] = "X-Mailer: PHP/".phpversion();
if (mail($to,$name,$fullmessage,implode("\r\n",$headers))
{
$message = 'Nachricht wurde gesendet!';
echo "<SCRIPT type='text/javascript'>
alert('$message');
window.location.replace(\"https://gerber-web.ch/kontakt.html\");
</SCRIPT>";
} else
{
echo "Fehler beim Senden der Mail.";
}
?>