好的,所以我一直在尝试设置自己的联系表单,因为这是我第一次走出CMS设置,如Wordpress和Joomla,这给我带来了一些困难,因为这些通常都是为你做的,而不是要求你自己编写任何代码。
我已经设法使用我找到的示例来设置我的表单,但这些都没有包含复选框选项,因此我无法查看其他工作并从中找到它。
<form class="form-horizontal" method="post" action="mailertest.php">
<fieldset>
<!-- Form Name -->
<legend>Form Name</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="cfname">Name</label>
<div class="col-md-4">
<input id="cfname" name="cfname" placeholder="Enter name here..." class="form-control input-md" required type="text">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="cfnumber">Phone Number</label>
<div class="col-md-4">
<input id="cfnumber" name="cfnumber" placeholder="Optional" class="form-control input-md" type="text">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="cfemail">eMail</label>
<div class="col-md-4">
<input id="cfemail" name="cfemail" placeholder="Enter eMail here..." class="form-control input-md" required type="text">
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="cfmessagebox">Message</label>
<div class="col-md-4">
<textarea class="form-control" id="cfmessagebox" name="cfmessagebox"></textarea>
</div>
</div>
<!-- Multiple Checkboxes -->
<div class="form-group">
<label class="col-md-4 control-label" for="cfselection">What would you like to talk about today?</label>
<div class="col-md-4">
<div class="checkbox">
<label for="cfselection-0">
<input name="cfselection" id="cfselection-0" value="" type="checkbox">
Website Design
</label>
</div>
<div class="checkbox">
<label for="cfselection-1">
<input name="cfselection" id="cfselection-1" value="" type="checkbox">
Search Engines and Ranking
</label>
</div>
<div class="checkbox">
<label for="cfselection-2">
<input name="cfselection" id="cfselection-2" value="" type="checkbox">
Social Media Marketing and Campaigns
</label>
</div>
<div class="checkbox">
<label for="cfselection-3">
<input name="cfselection" id="cfselection-3" value="" type="checkbox">
Other
</label>
</div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="cfsubmit"></label>
<div class="col-md-4">
<button id="cfsubmit" name="cfsubmit" class="btn btn-success">Submit</button>
</div>
</div>
</fieldset>
</form>
这是mailertest.php文件
<?php
if(isset($_POST['cfsubmit']))
{
$message=
'Name: '.$_POST['cfname'].'<br />
Phone: '.$_POST['cfphone'].'<br />
Email: '.$_POST['cfemail'].'<br />
Message: '.$_POST['cfmessage'].'
';
require "phpmailer/class.phpmailer.php"; //include phpmailer class
require "phpmailer/class.smtp.php";
// 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->Host = "xxx"; //Gmail SMTP server address
$mail->Port = xxx; //Gmail SMTP port
// Authentication
$mail->Username = "xxxx"; // Your full Gmail address
$mail->Password = "xxxx"; // Your Gmail password
// Compose Message to Send
$mail->SetFrom($_POST['cfemail'], $_POST['cfname']);
$mail->AddReplyTo($_POST['cfemail'], $POST['cfname']);
$mail->Subject = "New Customer Question via Contact Page";
$mail->MsgHtml($message);
// Send To
$mail->AddAddress("xxxxxx", "Recipient Name"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
}
?>
我一直在四处寻找一些我可以学习的例子,但到目前为止,我所尝试的一切都没有成功,如果有人愿意提供他们的帮助/建议甚至指出我正确的方向我将非常感激
由于
约旦
P.S我猜它会与价值有关,但我不知道在哪里可以找到一些这样的例子来弄清楚如何将他们的选择(价值)发送到我的电子邮件地址。
答案 0 :(得分:0)
首先需要为复选框设置值。
然后相应地在php中添加复选框行。
$message=
'Name: '.$_POST['cfname'].'<br />
Phone: '.$_POST['cfphone'].'<br />
Email: '.$_POST['cfemail'].'<br />
Message: '.$_POST['cfmessage'].'
Checkbox: '.$_POST['cfselection'].' // Add this line
';
试试:)