Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
点击";提交;打开php文件而不是运行脚本_Php_Contact Form - Fatal编程技术网

点击";提交;打开php文件而不是运行脚本

点击";提交;打开php文件而不是运行脚本,php,contact-form,Php,Contact Form,语法如果我更改 根据您在问题中提供的代码,我看到的唯一可能导致这种情况发生的问题是您在php语法上有拼写错误。例如:我引用你的评论: php文件位于web服务器上。我的意思是,通过在浏览器中打开index.html并上传到web服务器,我已经在本地对其进行了测试 无法在.html文件上编写PHP代码-将索引文件的扩展名更改为.PHP。如果您转到不在web服务器上的链接,则不会执行您的内容。它需要web服务器来执行PHP。我没有看到任何来自PHP的页面输出,因此我希望不会看到任何结果。PHP文

语法如果我更改


根据您在问题中提供的代码,我看到的唯一可能导致这种情况发生的问题是您在php语法上有拼写错误。例如:

我引用你的评论:


php文件位于web服务器上。我的意思是,通过在浏览器中打开index.html并上传到web服务器,我已经在本地对其进行了测试


无法在.html文件上编写PHP代码-将索引文件的扩展名更改为.PHP。

如果您转到不在web服务器上的链接,则不会执行您的内容。它需要web服务器来执行PHP。我没有看到任何来自PHP的页面输出,因此我希望不会看到任何结果。PHP文件位于web服务器上。我的意思是我已经在本地测试了它,在浏览器中打开index.html,然后上传到web服务器。您希望显示什么?更改为index.php,并将结束php标记更改为
?>
,而不是
@LiamG done,错误仍然存在。他的语法是速记php,如果在配置中打开了它就可以了。没有看到
>?
应该在哪里
?>
这不完全正确。您可以让任何扩展运行任何类型的代码。URL重写在这个现代web开发时代非常流行。他没有提到他正在使用URL重写的事实。如果他那样做,我同意you@YlberVeliu我这样做了,结果是一样的。
<form action="form_process.php" method="post" class="form" id="form1">

  <p class="name">
    <input name="name" type="text" placeholder="Name" id="name" class= "feedback-input" value="<?= $name ?>"/>
    <span class="error"><?= $name_error ?></span>
  </p>

  <p class="email">
    <input name="email" type="text" id="email" placeholder="Email" class= "feedback-input" value="<?= $email ?>"/>
    <span class="error"><?= $email_error ?></span>
  </p>

  <p class="text">
    <textarea name="message" type="text" id="comment" placeholder="Message" class= "feedback-input" value="<?= $message ?>"></textarea>
  </p>

  <div class="submit">
    <input type="submit" value="Submit" id="button-blue"/>
    <div class="ease"></div>
  </div>
  <div class="success"><?= $success; ?></div>
</form>
    <?php 

// define variables and set to empty values
$name_error = $email_error = "";
$name = $email = $message = $success = "";

//form is submitted with POST method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["name"])) {
    $name_error = "Name is required";
  } else {
    $name = test_input($_POST["name"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
      $name_error = "Only letters and white space allowed"; 
    }
  }

  if (empty($_POST["email"])) {
    $email_error = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $email_error = "Invalid email format"; 
    }
  }

  if (empty($_POST["message"])) {
    $message = "";
  } else {
    $message = test_input($_POST["message"]);
  }

  if ($name_error == '' and $email_error == '' ){
      $message_body = '';
      unset($_POST['submit']);
      foreach ($_POST as $key => $value){
          $message_body .=  "$key: $value\n";
      }

      $to = 'xxx@xxx.com';
      $subject = 'Contact Form Submit';
      if (mail($to, $subject, $message)){
          $success = "Message sent, thank you for contacting us!";
          $name = $email = $message = '';
      }
  }

}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}