0

I just got into web designing and this is the first attempt at an Email sheet. I'm not 100 percent as to what I'm doing wrong here but when I hit submit my information is not sent and the data does not disappear. Can someone help me out and possibly show me a suggestion.

I have already tried the Mailto: action and it won't even open Microsoft outlook. Is it possible that this is because it's in my repository (it has been deployed so that I can see it live as well) and not the clients actual domain.?

HTML

      <form action="contact-form.php" method="POST">

      <label for="fname">First Name</label>
      <input type="text" id="fname" name="firstname" placeholder="Your 
      name..">

      <label for="lname">Last Name</label>
      <input type="text" id="lname" name="lastname" placeholder="Your last 
      name..">

      <label for="email">Email</label>
      <input type="text"  id="email" name="email" 
      placeholder="contactme@email.com...">

      <label for="message">Message</label>
      <textarea id="message" name="message" placeholder="Write message 
      here..." style="height:200px"></textarea>

      <input type="submit" value="Submit">

    </form>

PHP

    if (isset($_POST['submit'])) {
    echo "error; you must complete this form"
    }
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    if(empty($fname)||empty($lname)||empty($email)||empty($message))
    {
    echo "Please fill in all applicable fields!";
    exit;
    }

    $email_from = 'contact@10keybookkeeping.com';
    $email_subject = "New Email from "$fname $lname;
    $email_body = "Message from $fname $lname. \n \n".
    "email address: $email \n".
    "Message: $message".

     $to = "contact@10keybookkeeping.com";
     $headers = "From: $email_from \r \n";

     mail($to,$email_subject,$email_body.$header)
  • your submit is missing a name, your input names don't match the array keys in post –  May 27 '19 at 23:16

1 Answers1

-2

probable you have problem with your php. Im not sure for this. this is my attempt about contact form. let you will see.

    <?php
include "db_connect.php";
include 'db_config.php';


if(isset($_POST['create'])) {
    $conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
    $name = $_POST['name'];
    $email = $_POST['email'];
    $text = $_POST['subject'];

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql = "INSERT INTO contact (name,email, text)
    VALUES ('$name', '$email', '$text')";

    if ($conn->query($sql) === TRUE) {
        echo "successful";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
}
?>