正如我的讨论标题所说。表单在提交所有相应信息时工作正常,但不发送"评论"部分。任何帮助将不胜感激。
这是我的表格代码:
<form role="form" id="footerform" name="footform" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<div class="form-group"> <span id="footformerror" class="error"></span>
<input name="footname" id="footname" class="form-control input-sm" placeholder="First Last" pattern="[A-Za-z]+ [A-Za-z]+" value="<?php if (isset($footname)) { echo $footname;} ?>" />
<?php if (isset($err_footname)) { echo $err_footname;}?>
<?php if (isset($err_footpatternmatch)) { echo $err_footpatternmatch;}?>
</div>
<div class="form-group">
<input type="email" name="footemail" class="form-control input-sm" id="footemail" autocomplete="off" required pattern="^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$" placeholder="example@email.com" value="<?php if (isset($footemail)) { echo $footemail;} ?>" />
</div>
<div class="form-group">
<textarea type="text" name="footcomments" id="footcomments" class="form-control input-sm" rows="6" placeholder="Comments" required></textarea>
<?php if (isset($footcomments)) { echo $footcomments; } ?>
</div>
<button type="submit" name="footsend" class="btn btn-default btn-xs" >Submit</button>
<input type="reset" value="Reset!" class="btn btn-default btn-xs">
</form>
这是我的PHP编码:
if(isset($_POST['footsend'])) {
if (isset($_POST['footname'])) { $footname = $_POST['footname']; } else { $footname = '';}
if (isset($_POST['footemail'])) { $footemail = $_POST['footemail']; }else { $footemail = '';}
if (isset($_POST['footcomments'])) {$footcomments = filter_var($_POST['footcomments'], FILTER_SANITIZE_STRING );
}
if (isset($_POST['ajaxrequest'])) { $ajaxrequest = $_POST['ajaxrequest']; } else { $footcomments = '';}
$footformerrors = false;
if ($footname === '') :
$err_footname = '<div class="error">Sorry, your name is a required field</div>';
endif; // input field empty
if ( !(preg_match('/[A-Za-z]+ [A-Za-z]+/', $footname)) ) :
$err_footpatternmatch = '<div class="error">Sorry, the name must be in the format: First Last</div>';
endif; // pattern doesn't match
if ( !(preg_match('/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/', $footemail)) ) :
$err_footemail = '<div class="error">Sorry, enter valid email address</div>';
endif; // pattern doesn't match
if (strlen($footcomments) < 2) :
$err_footcomments = '<div class="error">Please enter you comment.</div>';
endif; // input field empty
error_reporting(E_ERROR | E_PARSE);
$footemail_to = 'example@email.com';
$footemail_subject = 'Website Footer Comment Submission';
$footemail_from = $footemail;
$footemail_contact = $footname;
$footemail_message = "Email submission from ".$footname." at scdesignprint.net footer comments section.\n\n";
function clean_string($string) {
$bad = array('content-type','bcc:','to:','cc:','href');
return str_replace($bad,"",$string);
}
$footemail_message .= "Name: ".clean_string($footname)."\n";
$footemail_message .= "Email: ".clean_string($footemail)."\n";
$footemail_message .= "Comments: ".clean_string($footcomments)."\n";
$footheaders = "From: ".$footemail_from."\r\n".
"Reply-To: ".$footemail_contact."\r\n" ;
mail($footemail_to, $footemail_subject, $footemail_message, $footheaders);
答案 0 :(得分:0)
此行正在清除您的评论:
if (isset($_POST['ajaxrequest'])) { $ajaxrequest = $_POST['ajaxrequest']; } else { $footcomments = '';}
答案 1 :(得分:0)
这是使用HTML5和PHP的联系方式。对我有用
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
</form>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'contact@tangledindesign.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>