如何在netlify上运行php文件?

时间:2018-08-27 15:26:35

标签: php forms netlify

我建立了一个有表格的网站。联系表单在提交时重定向到contact.php。由于某种原因,每当我提交时,它都会显示找不到页面。

index.html

...
<form action="contact.php" method="post" enctype="text/plain">
  Name:<br>
  <input type="text" name="name" class="form-control" required><br>

  E-mail:<br>
  <input type="email" name="mail" class="form-control" required><br>

  Message:<br>
  <input type="text" name="comment" size="50"  class="form-control" required><br><br>

  <button type="submit" value="Send"> Send Message </button>
 </form>
 ...

contact.php

<?php

if($isset($_POST['submit']))
{
$name = $_POST['name'];
$mailFrom = $_POST['mail'];
$message = $_POST['comment'];

$mailTo = "sample@email.com";
$headers =  "From: ".$mailFrom;

mail($mailTo, $name, $message, $headers);

header("Location: index.html");
}
?>

我添加了一个build.sh文件,其中包含:

#!/bin/bash
php contact.php

我还在build命令中添加了./build.sh。我觉得我的剧本是错误的。请为我建议解决此问题的替代方法。

1 个答案:

答案 0 :(得分:5)

Netlify站点已部署到CDN并提供静态内容,尽管您可以在部署时运行PHP,但不能在页面请求期间执行PHP。

要提交表单,可以使用Netlify Forms或其他一些无服务器表单解决方案。