Bootstrap id="contactForm" form attribute preventing email to be sent

193 Views Asked by At

Can someone explain the problem here. I'm using bootstrap.

This executes the PHP and sends me an email:

 <form action="mailgun.php" method="post" role="form" name="sentMessage" novalidate>
...snip

This does not work:

 <form action="mailgun.php" method="post" role="form" name="sentMessage" id="contactForm" novalidate>
...snip

The difference is the ID attribute. Using Bootstrap this attribute gives me a nice "Your message has been sent". But it seems to clear the fields before it sends it to my PHP script. Any clues?

My PHP script:

<?php

  require 'mailgun/vendor/autoload.php';
  use Mailgun\Mailgun;

  // Check empty fields from input
  if(empty($_POST['name'])      ||
     empty($_POST['email'])     ||
     empty($_POST['message'])   ||
     !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
     {
     echo "You did not fill out all the required fields. Please try again.";
     return false;
     }

  // Sanitize
  $name = strip_tags(htmlspecialchars($_POST['name']));
  $email_address = strip_tags(htmlspecialchars($_POST['email']));
  $phone = strip_tags(htmlspecialchars($_POST['phone']));
  $message = strip_tags(htmlspecialchars($_POST['message']));

  // Instantiate the client.
  $mgClient = new Mailgun('this is removed');
  $domain = "this is removed";

  // Make the call to the client.
  $result = $mgClient->sendMessage($domain, array(
      'from'    => "this is removed",
      'to'      => "this is removed",
      'subject' => "this is removed",
      'text'    => "this is removed"
  ));

?>
0

There are 0 best solutions below