0

I am not familiar with php. I have searched similar questions to where I could not find a solution. I followed a fairly simply tutorial to add a send email functionality to a web app but I cannot get it to work as I get this error when testing to send an email to my yahoo. I would like to ask for help in figuring out a solution and or how I can make this code better. Thanks in advance

This is my error
Cannot POST /contactform.php

Here is my form code from my index.html

<form action="contactform.php" method="post">
                <div class="form-group">
                  <input type="text" name="name" placeholder="Full Name" class="form-control" id="name">
                </div>

                <div class="form-group">
                  <input type="text" name="email" placeholder="Email" class="form-control" id="email">
                </div>

                <div class="form-group">
                  <input type="text" name="subject" placeholder="Subject" class="form-control" id="message-text"></input>
                </div>

                <div class="form-group">
                  <textarea name="message" placeholder="Message" class="form-control" id="message-text"></textarea>
                </div>
                <button type="submit" name="submit" class="btn btn-outline-dark">Send message</button>
              </form>

And here is my contactform.php that is in the same folder as my index.html

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

    $name = $_POST['name'];
    $mailfrom = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    $mailTo =  "myemail@yahoo.com";
    $headers = "From: ".$mailfrom;
    $txt = "You have received an email from ".$name.".\n\n".$message;

    mail($mailTo, $subject, $txt, $headers);
    header("Location: index.html?mailsend");
    }

?>

0 Answers0