php - 如何将复选框选择传递给 php mailer 表单?
问题描述
复选框字段没有从我的 html 表单传递到我的电子邮件。
当用户填写表单时,我的电子邮件中会收到所有信息(用户名、电子邮件、电话、评论),但他们在表单上选中的框除外。我尝试将 [] like this name="feature[]" 放在名称字段中,但没有奏效,所以我恢复了原状。
我的表格……
<form name='quote' method="post" action="quote-request.php">
...
<center><h4 style='color:#C42D35'>Check each feature you will need:</h4></center>
<div class='row'>
<div class='col-md-6'>
<input type="checkbox" name="feature" value="something" checked> Basic <br>
<input type="checkbox" name="feature" value="something1"> Option 1 <br>
<input type="checkbox" name="feature" value="something2"> Option 2 <br>
</div>
<div class='col-md-6'>
<input type="checkbox" name="feature" value="something3"> Option 3 <br>
<input type="checkbox" name="feature" value="something4"> Option 4 <br>
</div>
</div>
...
</form>
我的处理程序(quote-request.php)...
<?php
if(isset($_POST['email'])) {
$email_to = "myemail@mydomain.com";
$email_subject = "Quote Request";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['firstName']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['feature']) ||
!isset($_POST['comment'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$firstName = $_POST['firstName']; // required
$email_from = $_POST['email']; // required
$phone = $_POST['phone']; // not required
$feature = $_POST['feature']; // required
$comment = $_POST['comment']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$firstName)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comment) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($firstName)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($phone)."\n";
$email_message .= "Comments: ".clean_string($comment)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
解决方案
推荐阅读
- sql - SQL 查询以获取最后 10 个带有回复的主题
- android - 捕获的图像可以保存到图像文件夹,但不能保存到应用程序文件夹
- asp.net-mvc - 在 Asp.net Mvc 的局部视图中显示模态
- android - 从智能手机向 Wear OS 智能手表发送通知
- android - Android Room:自动增量字段
- android - 从互联网上获取当前时间是一种好习惯吗?
- java - 填充有 Firebase 数据库的 Android 微调器未选择该项目
- spring-mvc - 什么时候调用 DispatcherServlet 的 onRefresh 方法?
- python - 使用 Python - 设置列表来存储 30 个学生姓氏以及 test1 和 test2 的测试分数,这两个分数都是 50
- matlab - 如何使用图形作为函数来获得输出?