-1

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.";
 }
?>
Orion
  • 359
  • 1
  • 2
  • 13
  • Possible duplicate of [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) –  Jul 02 '19 at 22:03
  • Check your mail server's log rather than your web server. – Synchro Jul 02 '19 at 22:24
  • I can't, my hosting provider doesn't give them out. Also it can't be a duplicate as i get internal server error 500 – Orion Jul 03 '19 at 09:45

1 Answers1

0

Found the error, there was a ) missing at the phpmail function.

Orion
  • 359
  • 1
  • 2
  • 13