0

好的,所以我一直在尝试设置我自己的联系表格,因为这是我第一次走出 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);

}
?>

我一直在寻找一些我可以从中学习的例子,但到目前为止,我所尝试的一切都没有奏效,所以如果有人愿意提供他们的帮助/建议,甚至为我指明正确的方向,我将不胜感激。

谢谢

约旦

PS我猜这与价值有关,但不知道在哪里可以找到一些例子来弄清楚如何将他们的选择(价值)发送到我的电子邮件地址。

4

1 回答 1

0

您首先需要为复选框设置值。

然后相应地在 php 中添加复选框行。

$message=
'Name:   '.$_POST['cfname'].'<br />
Phone:   '.$_POST['cfphone'].'<br />
Email:   '.$_POST['cfemail'].'<br />
Message: '.$_POST['cfmessage'].'
Checkbox: '.$_POST['cfselection'].' // Add this line
';

试试看:)

于 2014-05-13T09:17:14.703 回答