0

OK、私は自分の連絡先フォームを設定しようとしてきました。Wordpress や Joomla などの CMS 設定の外に出るのはこれが初めてなので、これらの中では通常すべてが行われ、あなたがする必要はありません。自分でコードを書いてください。

見つけた例を使用してフォームを設定することができましたが、これらのどれにもチェックボックスオプションが含まれていなかったため、別の作業を表示してそこから理解する方法がありませんでした.

  <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 に答える