我的phpmail代码突然停止工作,但一切似乎都还好

时间:2019-07-02 21:56:47

标签: php html phpmailer

我的代码以前工作过,现在突然停止工作了,有人可以告诉我为什么吗?

我看不到错误日志,因为它们没有被记录下来并且以某种方式为空

我要从html表单中请求所有字段,并且在提交时应发送邮件。

标题部分是否可能有错误?我真的不确定,因为我看不到日志。

<?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.";
 }
?>

1 个答案:

答案 0 :(得分:0)

发现错误,phpmail函数缺少)。