7

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

I added a build.sh file containing:

#!/bin/bash
php contact.php

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

Sohel Shaikh
  • 400
  • 1
  • 8
  • 18

3 Answers3

21

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.

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

talves
  • 13,993
  • 5
  • 40
  • 63
1

I recommend using InfinityFree for hosting the PHP site for free. or if your need is just to send an email form and the rest is static pages then i recommend emailjs that will let you send emails for free. so that you can deploy your site in netlify or vercel

Sunil Sapkota
  • 918
  • 2
  • 11
  • 24
-1

You can use 000webhost.com hosting for uploading your php projects.