我在这个页面上有两个表格。第一个有效。第二个没有。
建议的答案没有解决我的问题的任何答案。他们建议检查错误消息(我已经报告了我在问题底部收到的错误消息)。此外,该问题的答案都没有被解释为解决问题。这似乎是我的代码的问题,因为其中一个表单在SAME页面上正常工作。所以,这种形式一定有问题。
联系页面PHP:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" href="_images/icon_180.png">
<link rel="apple-touch-icon" sizes="76x76" href="_images/icon_76.png">
<link rel="apple-touch-icon" sizes="120x120" href="_images/icon_120.png">
<link rel="apple-touch-icon" sizes="152x152" href="_images/icon_152.png">
<link rel="apple-touch-icon" sizes="167x167" href="_images/icon_167.png">
<link rel="apple-touch-icon" sizes="180x180" href="_images/icon_180.png">
<title>Southeast Jeet Kune Do | Augusta, GA | Contact</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css">
<link rel="stylesheet" href="_css/styles.css?v=1.0.3">
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-63178620-3', 'auto');
ga('send', 'pageview');
</script>
<script async src='//www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics --></head>
<script>
function validateForm() {
var x = document.forms["myForm"]["name"].value;
var y = document.forms["myForm"]["address"].value;
var z = document.forms["myForm"]["message"].value;
if (x == null || x == "" || y == null || y == "" || z == null || z == "") {
alert("Please fill out all required fields before you submit your message.");
return false;
}
}
function validateForm2() {
var x = document.forms["myForm2"]["name"].value;
var y = document.forms["myForm2"]["address"].value;
var z = document.forms["myForm2"]["message"].value;
if (x == null || x == "" || y == null || y == "" || z == null || z == "") {
alert("Please fill out all required fields before you submit your message.");
return false;
}
}
</script><body>
<header>
<div class="container">
<a href="index.php"><img src="_images/logo_small_text.png" alt="Southeast Jeet Kune Do Logo"></a>
<i class="zmdi zmdi-menu"></i>
</div>
</header>
<figure class="overlay"></figure>
<nav>
<img src="_images/logo_nav.png" alt="">
<ul>
<li>
<a href="index.php">Home</a>
</li>
<li>
<a href="about.php">About</a>
</li>
<li>
<a href="styles.php">Styles</a>
</li>
<li class="category">
Classes
<ul>
<li><a href="classes_adults.php">Adults</a></li>
<li><a href="classes_kids.php">Kids</a></li>
<li><a href="classes_seminars.php">Seminars</a></li>
</ul>
</li>
<li>
<a href="schedule.php">Schedule</a>
</li>
<li>
<a href="pricing.php">Pricing</a>
</li>
<li>
<a href="faq.php">FAQ</a>
</li>
<li>
<a href="contact.php">Contact</a>
</li>
</ul>
</nav>
<main class="contact">
<h1>Contact</h1>
<section>
<div class="container">
<form name="myForm" id="myForm" method="post" action="mail.php" onsubmit="return validateForm()" class="contact-form">
<h2>Have Questions?</h2>
<p>Send us an email. We will contact you shortly!</p>
<input type="text" placeholder="Name (required)" name="name">
<input type="hidden" name="email">
<input type="email" placeholder="Email Address (required)" name="address">
<input type="tel" placeholder="Phone Number" name="phone">
<textarea name="message" id="" cols="30" rows="3" placeholder="Comments (required)"></textarea>
<input type="submit">
</form>
<span class="desktop">
<h2>Phone Number</h2>
<p>706.364.8127</p>
<h2>Address</h2>
<p>4158 Washington Rd<br>Evans, GA 30809</p>
</span>
<span class="mobile">
<a href="tel:706.364.8127"><button>Call Us</button></a>
<a href="http://maps.apple.com/?daddr=4158+Washington+Rd+Evans,+GA+30809&dirflg=d&t=m"><button>Get Directions</button></a>
</span>
</div>
</section>
</main>
<script>
$('.zmdi-menu, figure.overlay').click(function(){
$('nav').toggleClass('show');
$('figure.overlay').fadeToggle(500);
})
$('.category').click(function(){
$(this).toggleClass('active');
$('ul', this).slideToggle();
});
$('#reveal_button').click(function(){
$(this).fadeOut(500);
$('.form_hidden').delay(500).slideDown(500);
});
</script>
<footer>
<div class="container cf">
<div class="four">
<ul>
<li>Menu</li>
<li><a href="index.php">Home</a></li>
<li><a href="about.php">About</a></li>
<li><a href="styles.php">Styles</a></li>
<li><a href="classes_adults.php">Classes</a></li>
<li><a href="schedule.php">Schedule</a></li>
<li><a href="pricing.php">Pricing</a></li>
<li><a href="faq.php">FAQ</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</div>
<div class="four">
<ul>
<li>Social</li>
<li><a href="https://www.facebook.com/SoutheastJKD/" target="_blank">Facebook</a></li>
<li><a href="https://twitter.com/southeastjkd" target="_blank">Twitter</a></li>
<li><a href="https://www.instagram.com/southeastjeetkunedo/" target="_blank">Instagram</a></li>
</ul>
</div>
<div class="four">
<ul>
<li>Contact Info</li>
<li>706.364.8127</li>
<li>4158 Washington Rd<br>
Evans, GA 30809</li>
</ul>
</div>
<div class="four">
<h2>Have Questions?</h2>
<p>Send us an email. We will contact you shortly!</p>
<form name="myForm2" id="myForm2" method="post" action="mail.php" onsubmit="return validateForm2()" class="contact-form footer">
<input type="text" placeholder="Name (required)" name="name">
<input type="hidden" name="email">
<input type="email" placeholder="Email Address (required)" name="address">
<input type="tel" placeholder="Phone Number" name="phone">
<textarea name="message" id="" cols="30" rows="3" placeholder="Comments (required)"></textarea>
<input type="submit">
</form>
</div>
</div>
</footer></body>
</html>
mail.php:
<?php
if ( $_POST['email'] != '' ) {
die("You are a bot!");
} else {
$name = $_POST['name'];
$email = $_POST['address'];
$phone = $_POST['phone'];
$comments = $_POST['message'];
require_once 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try {
$mail->AddAddress('bboysupaman@gmail.com');
$mail->AddCC("jesse@happyninja.io");
$mail->SetFrom($email, $name);
$mail->Subject = 'Southeast JKD Contact Form';
$mail->MsgHTML("Name: $name<br><br>Email: $email<br><br>Phone: $phone<br><br>Comments: $comments");
$mail->Send();
header("Location: http://southeastjkd.com/success.php");
} catch (phpmailerException $e) {
header("Location: http://southeastjkd.com/failure.php");
} catch (Exception $e) {
header("Location: http://southeastjkd.com/failure.php");
}
}
?>
我花了很多时间用谷歌搜索并浏览我的代码。也许我忽略了一些简单的......但是,我无法弄清楚为什么第二种形式(myForm2)不起作用!有什么想法吗?
捕获的错误很简单:“无法实例化邮件功能。”