这是feedbackform.php :(使用phpmailer)
<?php
if (isset($_POST['submit'])) {
$message = 'Full Name: ' . $_POST['fullname'] . '<br />
Subject: ' . $_POST['subject'] . '<br />
Phone: ' . $_POST['phone'] . '<br />
Email: ' . $_POST['emailid'] . '<br />
Comments: ' . $_POST['comments'] . '
';
require "PHPMailer/PHPMailerAutoload.php"; //include phpmailer class
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "tsl"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 587; //Gmail SMTP port
//$mail->Encoding = '7bit';
// Authentication
$mail->Username = "abc@abc.com"; // Your full Gmail address
$mail->Password = "abc"; // Your Gmail password
// Compose
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "New Contact Form Enquiry"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress("abc@gmail.com", "abc"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Starter Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="public/customCss/starter-template.css" rel="stylesheet">
<link href="public/bootstrapValidation/css/formValidation.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="row">
<div class="panelc">
<div class="col-sm-6 col-md-8">
<div class="thumbnail1">
<div>
<form id="registration-form" method="post" class="form-horizontal" name="registration-form" action="" autocomplete="off">
<div class="form-group">
<label class="col-sm-3 control-label" for="fullname">Name</label>
<div class="col-sm-8 selectContainer">
<input type="text" class="form-control" id="fullname" name="fullname" placeholder="Your name"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="emailid">Email</label>
<div class="col-sm-8 selectContainer">
<input type="email" class="form-control" id="emailid" name="emailid" placeholder="Your name"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="subject">Subject</label>
<div class="col-sm-8 selectContainer">
<input type="text" class="form-control" id="subject" name="subject" placeholder="Your name"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="phone">phone</label>
<div class="col-sm-8 selectContainer">
<input type="text" class="form-control" id="phone" name="phone" placeholder="Your name"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="comments">Message</label>
<div class="col-sm-8 selectContainer">
<textarea class="form-control" rows="5" id="comments" name="comments"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-xs-5 col-xs-offset-6">
<input type="submit" class="btn btn-success" name="submit" value="Submit">
<input type="submit" name="submit" value="Send" />
</div>
</div>
</form>
<div>
<p><?php if (!empty($message)) echo $message; ?></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="public/bootstrap/js/bootstrap.min.js"></script>
<script src="public/bootstrapValidation/js/framework/bootstrap.min.js"></script>
<script src="public/customScript/validateform.js"></script>
<script src="public/bootstrapValidation/js/formValidation.min.js"></script>
</body>
</html>
<script src="public/customScript/validateform.js"></script>
无需点击两次。 答案 0 :(得分:0)
听起来您的javascript正在拦截表单提交,验证,但如果验证成功则不会继续提交,因此问题出在验证中,而不是PHP或HTML部分。如果验证失败,那么当然它应该无法提交 - 这就是验证的重点。
虽然我在这里,但不要这样做:
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
这将导致您的邮件无法通过SPF检查。将该信息放在邮件正文和回复中(正如您所做),但将发件人地址设置为您自己的地址,而不是提交者,如下所示:
$mail->SetFrom("abc@gmail.com", "abc");
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->AddAddress("abc@gmail.com", "abc");
这意味着来自地址不是伪造的,也不会使SPF检查失败,但您将能够直接回复提交者。