Bootstrap id =" contactForm"表单属性阻止发送电子邮件

时间:2016-12-19 21:39:40

标签: php html5 contact-form mailgun

有人可以在这里解释这个问题。我使用bootstrap。

执行PHP并向我发送电子邮件:

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

这不起作用:

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

区别在于ID属性。使用Bootstrap这个属性给了我一个很好的&#34;你的消息已被发送&#34;。但它似乎在将字段发送到我的PHP脚本之前清除字段。有线索吗?

我的PHP脚本:

<?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 个答案:

没有答案