发布到php表单后出现白屏

时间:2018-11-26 08:56:45

标签: php forms email fatal-error

我对php很陌生,但是在其他语言方面有很多经验。

我正在尝试制作一个简单的php联系表格。

从邮件发送的角度来看,它可以正常工作,但是由于某些原因,发布内容后,我收到了死亡的白屏。

我在php运行的父目录中没有收到任何错误日志,这是生成它们的地方。我还通过语法检查器运行了它,没有问题。

下面是代码:

<?php
if(isset($_POST['email'])) {

  // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "test@gmail.com";
    $email_subject = "You have received a message". " " . $_POST['subject'];

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }


    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['message'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');
    }



    $name = $_POST['name']; // required
    $email = $_POST['email']; // required
    $subject = $_POST['subject']; // not required
    $message = $_POST['message']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';



  if(!preg_match($email_exp,$email)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }

  if(strlen($name) < 2) {
    $error_message .= 'Please enter your name<br />';
  }

  if(strlen($message) < 2) {
    $error_message .= 'Please enter a message.<br />';
  }

  if(strlen($error_message) > 0) {
    died($error_message);
  }

    $email_message = "Form details below.\n\n";


    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }



    $email_message .= "お名前: ".clean_string($name)."\n";
    $email_message .= "メールアドレス: ".clean_string($email)."\n";
    $email_message .= "メッセージ: ".clean_string($message)."\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);

}
?>

0 个答案:

没有答案