我是PHP的新手,我正在尝试创建一个PHP表单字段,我有四个名为Output1,Output2,Output3和Output4的“复选框”但是当我选择所有四个复选框时它只发送一个而不是所有四个值。
注意我还有其他字段,但我只是想为您提供输出的HTML表单信息。
以下是HTML:
<form id="surveyForm" class="form" action="mailsurvey.php" method="post" name="surveyForm" enctype="multipart/form-data" onsubmit="return ValidateContactForm2();">
<input id="Output1" type="checkbox" name="Output1" value="Isolated" />
<input id="Output2" type="checkbox" name="Output2" value="Isolated" />
<input id="Output3" type="checkbox" name="Output3" value="Isolated" />
<input id="Output4" type="checkbox" name="Output4" value="Isolated" />
</form>
PHP代码:
<?php
require("includes/class.phpmailer.php");
require("includes/class.smtp.php");
require("includes/class.pop3.php");
if($_FILES['headshot']['name']!="")
{
$imgtype=explode('.',$_FILES['headshot']['name']);
$len=sizeof($imgtype);
$image_file=uniqid().'.'.$imgtype[$len-1];
$tmppath='uploads/';
move_uploaded_file($_FILES['headshot']['tmp_name'],$tmppath.$image_file);
$file_path=$tmppath.$image_file;
}
else
{
$file_path="";
}
if($_FILES['bodyshot']['name']!="")
{
$imgtype=explode('.',$_FILES['bodyshot']['name']);
$len=sizeof($imgtype);
$image_file=uniqid().'.'.$imgtype[$len-1];
$tmppath='uploads2/';
move_uploaded_file($_FILES['bodyshot']['tmp_name'],$tmppath.$image_file);
$file_path2=$tmppath.$image_file;
}
else
{
$file_path2="";
}
$mail = new PHPMailer();
$mail->Host = "localhost";
$mail->Mailer = "smtp";
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['Comments'];
$totalpower = $_POST['Total_Power']." ".$_POST['Total_Power2']." ".$_POST['Total_Power3']." ".$_POST['Total_Power4']." ".$_POST['Total_Power5'];
$input = $_POST['Input']." ".$_POST['Input2']." ".$_POST['Input3']." ".$_POST['Input4'];
$strings = $_POST['Strings4']." ".$_POST['Strings3']." ".$_POST['Strings2']." ".$_POST['Strings'];
$output = $_POST['Output1']." ".$_POST['Output2']." ".$_POST['Output3']." ".$_POST['Output4'];
$dimming = $_POST['Dimming4']." ".$_POST['Dimming3']." ".$_POST['Dimming2']." ".$_POST['Dimming'];
$packaging = $_POST['Packaging4']." ".$_POST['Packaging3']." ".$_POST['Packaging2']." ".$_POST['Packaging'];
$subject = "New Product Inquiry / Survey";
$body = "Name: " .$name. "<br> ".
"Company: " .$company. "<br>".
"Phone: " .$phone."<br>".
"Email: " .$email."<br><br><hr>".
"Total Power: " .$totalpower."<br>".
"Input: " .$input."<br>".
"Strings: " .$strings."<br>".
"Output: " .$output."<br>".
"Dimming: " .$dimming."<br>".
"Packaging: " .$packaging."<br>".
"Comments: " .$comments."<br>"
;
$mail->IsSMTP();
$mail->From = 'support@domain.com';
$mail->FromName = 'support@domain.com';
$mail->Subject = "New Product Inquiry";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
if($file_path!="")
{
$mail->AddAttachment($file_path);
}
if($file_path2!="")
{
$mail->AddAttachment($file_path2);
}
$mail->MsgHTML($body);
$mail->AddAddress('email@domain.com');
if(!$mail->Send())
{
$msg = "Unable to send email";
}
else
{
$msg = header("location: thank-you2.php");
}
?>
有人可以告诉我为什么如果用户选择所有四个框,此表单将不会发送所有输出字段。如果您有任何疑问,请告诉我。
谢谢,
谢
答案 0 :(得分:0)
我弄清楚我的问题是什么,以及为什么我想发布这个答案给别人注意的原因。
我的问题是我正在处理错误的PHP文件。我的网站中有两个相同的PHP文件,一个是在几个文件夹下刻录的,一个是在网站的根目录下。一个burred是我应该一直在进行更改的那个因为那是LIVE文件。当我上传一个无效的文件,因为它是错误的。我想通过仔细检查表单页面的表单元素中的路径。
<form id="surveyForm" class="form" **action="subfolder/formmailer_scripts/mailsurvey.php"** method="post" name="surveyForm" enctype="multipart/form-data" onsubmit="return ValidateContactForm2();">
因此,故事的主题是注意并确保你不要过分看待简单的事情。我浪费了大约一个小时来重新上传一个不是它需要的文件。希望这有助于他人!