0

I have a html page that has a contact form. I don't have captcha on it yet, but I'm trying to learn why this code doesn't work before jumping into that. So, my index.html has this form:

<form id="quote-form" action="inc/sendmail.php" method="post">
            <div class="sec-title text-center">
                <h1>Request for Quote</h1>
                <span class="border center"></span>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <input type="text" name="name" value="" placeholder="Your Name*" required="">
                    <input type="email" name="email" value="" placeholder="Your Mail*" required="">
                    <input type="text" name="phone" value="" placeholder="Your Phone*" required="">
                    <select class="selectmenu" name=message>
                        <option selected="selected">Select Service</option>
                        <option value="Need Quote on a product Alpha</option>
                        <option>Other</option>
                    </select>
                    <button class="thm-btn bg-clr1" type="submit">Get a Quote</button>
                </div>  
            </div>    
        </form>

My sendmail.php has this code:

<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$formcontent="From: $name \n Message: $message \n Email:$email \n Phone:$phone";
$recipient = "testname@gmail.com";
$subject = "Website Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Mail Sent. Thank you, we will contact you shortly.";
}
?>
  • 1st off, does your hosting company allow you to send out mail? 2nd : Is gmail even accepting it or just dumping it? – Forbs Dec 22 '17 at 19:19
  • What error are you seeing? – Cameron Hurd Dec 22 '17 at 19:22
  • 1
    You are checking: `if(isset($_POST['submit']))` but your form has no element named `submit`, so basically the condition will never be satisfied – Oliver Maksimovic Dec 22 '17 at 19:23
  • At the begining it was working, but I needed some type of validation so I added the if statement, and that i when it wouldn't work. I know the hosting company is allowing it. It neve makes to the destination mail server. I'm not using gmail that was just an example. – johndoeysmith Dec 22 '17 at 19:24
  • so, i could just name the submit button - submit? – johndoeysmith Dec 22 '17 at 19:27

2 Answers2

1

You can also add a name attribute on your submit button.

On your button add:

name='submit'

<button name='submit' class="thm-btn bg-clr1" type="submit">Get a Quote</button>

The reason for this is that the name attribute is what gets added to the $_POST array. For learning purposes, do a var_dump($_POST); and you'll see the result

Rotimi
  • 4,783
  • 4
  • 18
  • 27
-1

Per your comments above.

Change

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

to

 if (count($_POST) > 0) {
Forbs
  • 1,256
  • 1
  • 7
  • 9