0

PHP Email form not sending. Can someone look at my code to see if they notice something.

Below is the html form in my index.html

    <form class= "contact-form" action="php/send.php" method="post">
                <input type="text" name="subject" placeholder="Subject" required />
                <input type="email" name="email" type= "email" placeholder="Email" required />
                <textarea name="message" placeholder="Message" required></textarea>
                <input type="submit" name "submit" value"Send" class="sub-btn">

            </form>

Below is my php code to send

<?php
if(isset($_POST['submit'])){
    $subject = $_POST['subject'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $to = 'myemail@gmail.com';
    if(mail($to,$subject,$message)){
        echo "Sent Successfully! We will contact you shortly!";        
    }
    else
    {
        echo "Something went wrong!";
    }

    }
?>
user3783243
  • 5,368
  • 5
  • 22
  • 41
Klaidi Ziaj
  • 175
  • 2
  • 2
  • 11
  • 3
    `name "submit"` is a typo and might result in `if(isset($_POST['submit'])){` not firing. When you run this do you get `Sent Successfully` or `Something went wrong`, or nothing? – user3783243 Feb 15 '19 at 15:44
  • 2
    on your submit input you have `name "submit"` , try `name="submit"` – JGreatorex Feb 15 '19 at 15:45
  • it was changed to to name="submit" and i still do not receive any email. but it says sent successfully after i hit the submit button. – Klaidi Ziaj Feb 15 '19 at 15:57
  • Ok so I am getting an email but its not from the email address that is being submitted in the form. I am getting the email from my hostgator email account. I dont understand why. – Klaidi Ziaj Feb 15 '19 at 15:59
  • 3
    You didn't set a `From` header. You actually never use `$email` in your script. – user3783243 Feb 15 '19 at 16:10
  • Also, be careful with the From header. If the domain of your server does not match the domain of the email being sent, then this will often cause it to be rejected as spam. So, website.com can send an email as foo@website.com or bar@website.com, but not as foo@gmail.com, in shared hosting environments like GoDaddy, this means you often have to send using their name for the server instead of your domain meaning it is often better to leave the From field blank so that the server populates it for you. – Nosajimiki Feb 15 '19 at 16:33

1 Answers1

0

I see in your form HTML code you do not have = signs between your name and value in your last input value. The form HTML should be:

<form class= "contact-form" action="php/send.php" method="post">
  <input type="text" name="subject" placeholder="Subject" required />
  <input type="email" name="email" type= "email" placeholder="Email" required />
  <textarea name="message" placeholder="Message" required></textarea>
  <input type="submit" name="submit" value="Send" class="sub-btn">
</form>
That would cause the submit process to throw an error.
Jaime Argila
  • 408
  • 3
  • 13