一度送信ボタンを入力します。メールが送信されました。しかし、選択した値を送信する代わりに、リスト内のすべての値を送信します。私は何が欠けているかを見つけることができません。提案してください。PHPmailerで複数のチェックボックス値を送信
私が見た限り、私はそれに何らかの誤りはなかった。しかし、私は問題が通信部分にあると思う。 1を使用して構築
)HTML 2)のJavaScript 3)jqueryの 4)PHP 5)phpmailerの
任意の解決策を提案してください。
var address = document.getElementById('faddress');
var optiona = document.getElementById('optiona');
var optionb = document.getElementById('optionb');
var optionc = document.getElementById('optionc');
var optiond = document.getElementById('optiond');
var optione = document.getElementById('optione');
var optionf = document.getElementById('optionf');
var optiong = document.getElementById('optiong');
var optionh = document.getElementById('optionh');
var optioni = document.getElementById('optioni');
var optionj = document.getElementById('optionj');
var sectiona = document.getElementById('sectiona');
function checkErrors(){
var error_count = 0;
if(error_count == 0){
document.getElementById('container').innerHTML = "<div class='thank_con'><div class='thankyou'><h2>Thank You</h2><p>We will get back to you shortly.</p><a href='https://www.google.co.uk/' target='_blank'><img src='viewsite.png' class='imgcls'></a></div> </div>";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if(this.responseText == "OKAY"){
}
}
};
xhttp.open("GET", "comm.php? address="+address.value+"&optiona="+optiona.value+"&optionb="+optionb.value+"&optionc="+optionc.value+"&optiond="+optiond.value+"&optione="+optione.value+"&optionf="+optionf.value+"&optiong="+optiong.value+"&optionh="+optionh.value+"&optioni="+optioni.value+"&optionj="+optionj.value+"§iona="+sectiona.value);
xhttp.send();
}
}
document.getElementById("submit_button").addEventListener("click", function(){
checkErrors();
});
<form method="POST" name="contactform" action="contact-form-handler.php">
<input class="form-check-input " type="checkbox" name="optiona" id="optiona" value="ESOL - National 3: Ayr">
<input class="form-check-input " type="checkbox" name="optionb" id="optionb" value="ESOL - National 4: Kilmarnock/Kilwinning">
<input class="form-check-input " type="checkbox" name="optionc" id="optionc" value="ESOL - National 5: Ayr/Kilmarnock">
<input class="form-check-input " type="checkbox" name="optiond" id="optiond" value="ESOL - Higher: Ayr/Kilmarnock">
<input class="form-check-input " type="checkbox" name="optione" id="optione" value="PEZ: Ayr/Kilmarnock/Kilwinning">
<input class="form-check-input " type="checkbox" name="optionf" id="optionf" value="PEZ Plus: Ayr/Kilmarnock/Kilwinning /Cumnock">
<input class="form-check-input " type="checkbox" name="optiong" id="optiong" value="Step Into Employment: Kilwinning">
<input class="form-check-input " type="checkbox" name="optionh" id="optionh" value="Step Into Youthwork: Ayr">
<input class="form-check-input " type="checkbox" name="optioni" id="optioni" value="Twenty Four/Seven Plus: Ayr/Kilmarnock/Kilwinning">
<input class="form-check-input " type="checkbox" name="optionj" id="optionj" value="Princes Trust (Feb 18 start): Ayr/Kilmarnock/Kilwinning">
<input class="form-check-input " type="checkbox" name="sectiona" id="sectiona" value="Introduction to Business and Computing: Kilwinning">
<input type="text" class="textbx form-control" name="faddress" id="faddress" placeholder="Enter your email">
<button type="submit" name="submit" class="subsc" id="submit_button"></button>
</form>
Comm.php
<?php
date_default_timezone_set("America/New_York");
require 'PHPMailer/PHPMailerAutoload.php';
class MyDB extends SQLite3 {
function __construct() {
$this->open('south_bay.sqlite');
}
}
$address = $_GET['address'];
$optiona = $_GET['optiona'];
$optionb = $_GET['optionb'];
$optionc = $_GET['optionc'];
$optiond = $_GET['optiond'];
$optione = $_GET['optione'];
$optionf = $_GET['optionf'];
$optiong = $_GET['optiong'];
$optionh = $_GET['optionh'];
$optioni = $_GET['optioni'];
$optionj = $_GET['optionj'];
$sectiona = $_GET['sectiona'];
$monthNum = date("m");
$dateObj = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F');
$date = $monthName.date("-d-Y").' '.date("h:i:s A");
$mail = new PHPMailer();
$body = "<h1>Here are your customer details</h1>
<table border='1'>
<tr>
<td><p><strong> EMAIL ADDRESS: </strong>$address</p></td>
</tr>
<tr>
<td><p><strong> PARTNERSHIP AND EMPLOYABLITY COURSES - CAMPUS LOCATION</strong></p></td>
</tr>
<tr>
<td><p>$optiona</p></td>
</tr>
<tr>
<td><p>$optionb</p></td>
</tr>
<tr>
<td><p>$optionc</p></td>
</tr>
<tr>
<td><p>$optiond</p></td>
</tr>
<tr>
<td><p>$optione</p></td>
</tr>
<tr>
<td><p>$optionf</p></td>
</tr>
<tr>
<td><p>$optiong</p></td>
</tr>
<tr>
<td><p>$optionh</p></td>
</tr>
<tr>
<td><p>$optioni</p></td>
</tr>
<tr>
<td><p>$optionj</p></td>
</tr>
<tr>
<td><p><strong> BUSSINESS AND COUMPUTING</strong></p></td>
</tr>
<tr>
<td><p>$sectiona</p></td>
</tr>
</table>";
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "welcome$123"; // GMAIL password
$mail->AddAddress('[email protected]');
$mail->AddAddress('[email protected]');
$mail->SetFrom('[email protected]');
$mail->Subject = 'Contact Form';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
$mail->Send();
echo "OKAY";
?>
私は送信ボタンを入力すると。メールが送信されました。しかし、選択した値を送信する代わりに、リスト内のすべての値を送信します。私は何が欠けているかを見つけることができません。提案してください。
私が見た限り、私はそれに何らかの誤りはなかった。しかし、私は問題が通信部分にあると思う。 1を使用して構築
)HTML 2)のJavaScript 3)jqueryの 4)PHP 5)phpmailerの
任意の解決策を提案してください。
**ありがとうございます**単純な配列で動作しました。 –