gpt4 book ai didi

javascript - 使用 PHP 和 Bootstrap CSS 从复选框获取状态

转载 作者:行者123 更新时间:2023-11-28 08:03:02 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 和 bootstraps CSS 创建联系表单。现在我已经完成了大部分工作,但是我需要从多个复选框中获取状态,并仅在邮件中从选中的框中发布“标签”。我知道这不像我说的那么简单,我已经看到一些使用 javascript 或 Ajax 等的在线页面。但我无法让它工作,目前这是我的页面:

--更新--

再次感谢您的回答,但仍然收到 500 错误页面: http://prntscr.com/6u21xy

<?php
if(isset($_POST['submit']))
{

$message=
'Full Name: '.$_POST['fullname'].'<br />
Subject: '.$_POST['subject'].'<br />
Phone: '.$_POST['phone'].'<br />

foreach($_POST['check_list'] as $check) {
$message .= .$check . '<br>';
}


Email: '.$_POST['emailid'].'<br />
Comments: '.$_POST['comments'].'
';
require "PHPMailer-master/class.phpmailer.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 = "ssl"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 465; //Gmail SMTP port
$mail->Encoding = '7bit';

// Authentication
$mail->Username = "example@gmail.com"; // Your full Gmail address
$mail->Password = "examplepassword"; // 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("examplereceiver@gmail.com", "Mr. Example"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? '<div class="alert alert-success" role="alert"><strong>Success!</strong>Message Sent Successfully!</div>' : '<div class="alert alert-danger" role="alert"><strong>Error!</strong>There was a problem delivering the message.</div>';

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">
<title>Contact Form</title>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[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="contactform">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><a href="">Contact Form</a></h3>
</div>
<div class="panel-body">
<form name="form1" id="form1" action="" method="post">
<fieldset>
<input type="text" class="form-control" name="fullname" placeholder="Volledige Naam" />
<br />
<input type="text" class="form-control" name="subject" placeholder="Onderwerp" />
<br />
<input type="text" class="form-control" name="phone" placeholder="Telefoonnummer" />
<br />
<input type="email" class="form-control" name="emailid" placeholder="Email" />
<br />
<div class="checkbox">
<label>
<input type="checkbox" name="check_list[]" value="value1">Check me
</label>
<label>
<input type="checkbox" name="check_list[]" value="value2">Check me 2
</label>
</div>
<br />
<textarea rows="4" class="form-control" cols="20" name="comments" placeholder="Extra tekst indien gewenst"></textarea>
<br />
<input type="submit" class="btn btn-success"name="submit" value="Verstuur" />
</fieldset>
</form>
<p><?php if(!empty($message)) echo $message; ?></p>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>

最佳答案

<?php
if(isset($_POST['submit']))
{

$message=
'Full Name: '.$_POST['fullname'].'<br />
Subject: '.$_POST['subject'].'<br />
Phone: '.$_POST['phone'].'<br />';
foreach($_POST['check_list'] as $check) {
$message .= .$check . '<br>';
}



Email: '.$_POST['emailid'].'<br />
Comments: '.$_POST['comments'].'
';
require "PHPMailer-master/class.phpmailer.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 = "ssl"; // Connect using a TLS connection
$mail->Host = "mail.bjornvdakker.me"; //Gmail SMTP server address
$mail->Port = 465; //Gmail SMTP port
$mail->Encoding = '7bit';

// Authentication
$mail->Username = "support@bjornvdakker.me"; // Your full Gmail address
$mail->Password = "5#UPJucxaB7"; // 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("bjornvdakker@hotmail.com", "Mr. Example"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? '<div class="alert alert-success" role="alert"><strong>Success!</strong>Message Sent Successfully!</div>' : '<div class="alert alert-danger" role="alert"><strong>Error!</strong>There was a problem delivering the message.</div>';

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">
<title>Contact Form</title>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[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="contactform">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><a href="">Contact Form</a></h3>
</div>
<div class="panel-body">
<form name="form1" id="form1" action="" method="post">
<fieldset>
<input type="text" class="form-control" name="fullname" placeholder="Volledige Naam" />
<br />
<input type="text" class="form-control" name="subject" placeholder="Onderwerp" />
<br />
<input type="text" class="form-control" name="phone" placeholder="Telefoonnummer" />
<br />
<input type="email" class="form-control" name="emailid" placeholder="Email" />
<br />
<div class="checkbox">
<label>
<input type="checkbox" name="check_list[]" value="value1">Check me
</label>
<label>
<input type="checkbox" name="check_list[]" value="value2">Check me 2
</label>
</div>
<br />
<textarea rows="4" class="form-control" cols="20" name="comments" placeholder="Extra tekst indien gewenst"></textarea>
<br />
<input type="submit" class="btn btn-success"name="submit" value="Verstuur" />
</fieldset>
</form>
<p><?php if(!empty($message)) echo $message; ?></p>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>

将此添加到您的复选框:

<input type="checkbox" name="check_list[]" value="value1">

关于javascript - 使用 PHP 和 Bootstrap CSS 从复选框获取状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29636642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com