因此,根据我目前设置的内容,我可以使用php成功将信息发送到我的电子邮件收件箱。问题是我只能发送以文本形式输入的信息,例如contactName,contactEmail,contactPhone和contactMessage,但我无法发送与复选框相关的任何信息。我希望能够将每个复选框的值或名称发送到我的电子邮件收件箱以及其他我正在获取的信息。
这是我的PHP。实际上有更多的复选框,但为了简单起见,我删除了除了一个以外的所有复选框。我基本上试图将每个复选框名称添加到发送到我的收件箱的$ message中,但由于某些原因,没有任何复选框信息被添加到邮件中:
<?php
if(isset($_REQUEST['contactName'])){
$contactName = $_REQUEST['contactName'];
$contactEmail = $_REQUEST['contactEmail'];
$contactPhone = $_REQUEST['contactPhone'];
$contactMessage = $_REQUEST['contactMessage'];
$subject = "Information Request from " . $contactName;
$comment = "Additional Comments: " . $contactMessage;
$message = $contactName . "\n Phone Number: " . $contactPhone .
"\n Email address: " . $contactEmail .
"\n Additional Comments: " . $contactMessage . "\n\n" .
' has requested information on the following items:' . "\n\n";
if( isset($_REQUEST['gateway_or_hub'] ) )$message .= "gateway_or_hub\n";
$to = 'myName <myName@email.com>';
$add_headers = 'From: ' . $name . ' <' . $email .'>' . "\r\n";
if(mail($to,$subject,$message,$add_headers) == TRUE){
output_form_header_completed();
} else {
output_form_header_incompleted();
}
} else {
output_form();
}
?>
以下是我的HTML格式,其中包含一个复选框的格式:
<form name="products_form" id="products_form" action="./products.php" method="post">
<label class="mdl-checkbox mdl-js-checkbox" for="gateway_or_hub">
<input type="checkbox" id="gateway_or_hub" class="mdl-checkbox__input">
<span class="mdl-checkbox__label">HUB</span>
</label>
这是我的HTML提交按钮:
<button name="productsSubmit" id="productsSubmit" type="submit">SEND REQUEST</button>
这是我的Javascript:
$(function() {
});
$( "#productsClear" ).click(function() {
$('#contactErrorMessage').hide();
$('#contactName').text('');
$('#contactPhone').text('');
$('#contactEmail').text('');
$('#contactMessage').text('');
});
$( "#productsSubmit" ).click(function() {
$('#contactErrorMessage').hide();
// Check Name
var input=$('#contactName');
var is_name=input.val();
if(! is_name){
$('#contactErrorMessage').show();
$('#contactErrorMessage').text("Valid Name is requierd!")
return;
}
// Check Email
var input=$('#contactEmail');
var re = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
var is_email=re.test(input.val());
if(! is_email){
$('#contactErrorMessage').show();
$('#contactErrorMessage').text("Valid email is requierd!")
return;
}
console.log("Form should submit!");
$("#products_form").submit();
});