0

Could you please help me with my code? I have a contact form that is linked to a php. it is not sending emails. It just redirects me to my contact-form.php.

Heres the html:

<div class="wrapper">
  <h2>Contact us</h2>
  <div id="error_message"></div>
  <form id="myform" onsubmit="return validate();" action="contact-form.php">
    <div class="input_field">
        <input type="text" placeholder="Name" id="name">
    </div>
    <div class="input_field">
        <input type="text" placeholder="Subject" id="subject">
    </div>
    <div class="input_field">
        <input type="text" placeholder="Phone" id="phone">
    </div>
    <div class="input_field">
        <input type="text" placeholder="Email" id="email">
    </div>
    <div class="input_field">
        <textarea placeholder="Message" id="message"></textarea>
    </div>
    <div class="btn">
        <input type="submit">

    </div>
  </form>
</div>
<div class="home">
  <a class="" href="index.html">Back to main page</a>
</div>

here's the php:

<?php

    if (isset($_POST['submit'])) {

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

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

      mail($mailTo, $phone, $txt, $headers);
      header("Location:http://removedmysite.com/index.html")
}


 ?>

Thanks in advance!

Best regards.

user3783243
  • 5,368
  • 5
  • 22
  • 41
WidMor
  • 1
  • 2
    `` does not have a `name` so `if (isset($_POST['submit'])) {` is false.... also `
    ` without a method submits over `GET`
    – user3783243 Nov 20 '20 at 20:11
  • 1
    All of the PHP code is wrapped in a conditional which checks for a specific form element: `if (isset($_POST['submit']))` But the form doesn't have any element with that name. (In fact, none of the form elements have names.) So the PHP code literally does nothing. You need to add names to your form elements. For example: `` – David Nov 20 '20 at 20:12
  • Thank you! Rookie mistake form a rookie xD. It now redirects to the page that I want. – WidMor Nov 20 '20 at 21:05

0 Answers0