如何在netlify上运行php文件? [英] How to run php files on netlify?

查看:69
本文介绍了如何在netlify上运行php文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I build a website which has a form. Contact form redirects to contact.php on submit. For some reason whenever I submit, it says page not found.

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文件,其中包含:

I added a build.sh file containing:

#!/bin/bash
php contact.php

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

I also added ./build.sh in build command. I feel my script is wrong. Please suggest me alternatives to solve this problem.

推荐答案

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

A Netlify site is deployed to a CDN and serves up static content and although you can run PHP at the time of a deploy, you cannot execute PHP during a page request.

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

To submit a form, you can use Netlify Forms or some other serverless forms solution.

这篇关于如何在netlify上运行php文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆