PHP:表单电子邮件显示一些字段,而不是其他字段


PHP: Form emailing displaying some fields, not others?

这不是我的领域。我正在帮助一个朋友,我一直试图通过常识和谷歌来理清这个问题,但我想不出来。

简而言之:朋友在他的网站上有一个表单。表单通过一个PHP脚本,只要有人填写,就会通过电子邮件将结果发送给他。它已经工作了一段时间。他最近添加了一些新的字段,现在突然有些字段不返回结果通过PHP脚本通过表单提交。

下面是表单的HTML:

        <div id="contact-area">
            <form method="post" action="contactengine.php">
                <table>
                    <tr>
                        <td class="left"><label for="Name">Full Name:</label></td>
                        <td><input type="text" name="Name" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="EMT">EMT #:</label></td>
                        <td><input type="text" name="EMT" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="NREMT">NREMT #:</label></td>
                        <td><input type="text" name="NREMT" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="Email">Email:</label></td>
                        <td><input type="text" name="Email" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="Phone">Phone:</label></td>
                        <td><input type="text" name="Phone" /></td>
                    </tr>
                    <tr>
                        <td class="left"><label for="Address">Full Address:</label></td>
                        <td><textarea name="Address" rows="10" cols="20"></textarea></td>
                    </tr>
                    <tr>            
                        <td class="left"><label for="Program">Program(s):</label></td>
                        <td><input type="radio" value="EMT NCCR" name="Program"/><label>EMT NCCR</label><br />
                        <input type="radio" value="Paramedic NCCR" name="Program"/><label>Paramedic NCCR</label><br />
                                    <input type="radio" value="10 hours ConEd" name="Program"/><label>10 hours ConEd</label><br />
                                    <input type="radio" value="Snowbird EMS Conference" name="Program"/><label>Snowbird EMS Conference</label><br />
                                    <input type="radio" value="AHA ACLS" name="Program"/><label>AHA ACLS</label><br />
                                    <input type="radio" value="AHA PALS" name="Program"/><label>AHA PALS</label><br />
    </tr>
                        <tr>                
                        <td class="left"><label for="nccrtraining">Desired NCCR Training:</label></td>
                        <td><input type="radio" value="Online" name="nccrtraining" /><label>Online</label><br />
                            <input type="radio" value="DVD" name="nccrtraining"/><label>DVD</label><br  />
                        <input type="radio" value="USB" name="nccrtraining"/><label>USB Thumbdrive</label></td> 
                    </tr>  
                    <tr>
                        <td class="left"><label for="Operating">Operating System:</label></td>
                        <td><input type="radio" value="Windows" name="Operating" /><label>Windows</label><br />
                            <input type="radio" value="Mac" name="Operating"/><label>Mac</label></td>
                    </tr>   
                    <tr>
                        <td class="left"><label for="emt20hournccpcoursedate">EMT 20-hour NCCP Course Date:</label></td>
                        <td>
                        <input type="radio" value="September 26th, 2015 - 12:30PM" name="emt20hournccpcoursedate" /><label>September 26th, 2015 - 12:30PM</label><br />
            <input type="radio" value="October 17th, 2015 - 12:30PM" name="emt20hournccpcoursedate" /><label>October 17th, 2015 - 12:30PM</label><br />
                        <input type="radio" value="November 14th, 2015 12:30PM" name="emt20hournccpcoursedate" /><label>November 14th, 2015 12:30PM</label><br />
                        <input type="radio" value="December 5th, 2015 8:00AM" name="emt20hournccpcoursedate" /><label>December 5th, 2015 8:00AM</label><br />
                        <input type="radio" value="December 5th, 2015 10:30AM" name="emt20hournccpcoursedate" /><label>December 5th, 2015 10:30AM</label><br />
                       <input type="radio" value="December 5th, 2015 1:00PM" name="emt20hournccpcoursedate" /><label>December 5th, 2015 1:00PM</label><br />
    </tr>
    <tr>                
</tr>   
    <tr>
                        <td class="left"><label for="paramedic30hournccpcoursedate">Paramedic 30-hour NCCP Course Date:</label></td>
                        <td>
                        <input type="radio" value="July 17th, 2015 - 8:30AM" name="paramedic30hournccpcoursedate" /><label>July 17th, 2015 - 8:30AM</label><br />
            <input type="radio" value="August 7th, 2015 - 8:30AM" name="paramedic30hournccpcoursedate" /><label>August 7th, 2015 - 8:30AM</label><br />
                        <input type="radio" value="August 28th, 2015 8:30AM" name="paramedic30hournccpcoursedate" /><label>August 27th, 2015 8:30AM</label><br />
                        <input type="radio" value="December 4th, 2015 8:30AM" name="paramedic30hournccpcoursedate" /><label>December 4th, 2015 8:30AM</label><br />
                        <input type="radio" value="January 14th, 2016 8:30AM" name="paramedic30hournccpcoursedate" /><label>January 14th, 2016 8:30AM</label><br />
                       <input type="radio" value="February 29th, 2016 8:30AM" name="paramedic30hournccpcoursedate" /><label>February 29th, 2016 8:30AM</label><br />
    </tr>
    <tr>                
</tr>                   <tr>                    
                    <td class="left"><label for="aclsinitialcoursedate">2015 ACLS Initial Course Dates:</label></td>
                        <td>
                       <input type="radio" value="6/8 & 6/10 8AM" name="aclsinitialcoursedate" /><label> 6/8 & 6/10 8AM</label><br />
             <input type="radio" value="7/6 & 7/8 8AM" name="aclsinitialcoursedate" /><label> 7/6 & 7/8 8AM</label><br />
             <input type="radio" value="8/3 & 8/5 8AM" name="aclsinitialcoursedate" /><label> 8/3 & 8/5 8AM</label><br/>
             <input type="radio" value="9/18 & 9/25 8AM" name="aclsinitialcoursedate" /><label> 9/18 & 9/25 8AM</label><br />
         <input type="radio" value="11/6 & 11/13 8AM" name="aclsinitialcoursedate" /><label> 11/6 & 11/13 8AM</label><br /> 
                    <tr>                
                    <td class="left"><label for="aclsrecertcoursedate">2015 ACLS Recert Course Dates:</label></td>
                        <td>
                       <input type="radio" value="6/15 8AM" name="aclsrecertcoursedate" /><label> 6/15 8AM</label><br />
             <input type="radio" value="7/13 8AM" name="aclsrecertcoursedate" /><label> 7/13 8AM</label><br />
             <input type="radio" value="10/2 8AM" name="aclsrecertcoursedate" /><label> 10/2 8AM</label><br/>
             <input type="radio" value="11/20 8AM" name="aclsrecertcoursedate" /><label> 11/20 8AM</label><br/>     
    </tr>
    <tr>                
            <td class="left"><label for="palsinitialcoursedate">2015 PALS Initial Course Dates:</label></td>
                        <td>
                       <input type="radio" value="6/22 & 6/24 8AM" name="palsinitialcoursedate" /><label> 6/22 & 6/24 8AM</label><br />
             <input type="radio" value="7/20 & 7/22 8AM" name="palsinitialcoursedate" /><label> 7/20 & 7/22 8AM</label><br />
             <input type="radio" value="8/10 & 8/12 8AM" name="palsinitialcoursedate" /><label> 8/10 & 8/12 8AM</label><br/>
    <input type="radio" value="10/9 & 10/16 8AM" name="palsinitialcoursedate" /><label> 10/9 & 10/16 8AM</label><br/>        
                    <tr>                    
                    <td class="left"><label for="palsrecertcoursedate">2015 PALS Recert Course Dates:</label></td>
                        <td>
                       <input type="radio" value="6/29 8AM" name="palsrecertcoursedate" /><label> 6/29 8AM</label><br />
             <input type="radio" value="7/27 8AM" name="palsrecertcoursedate" /><label> 7/27 8AM</label><br />
             <input type="radio" value="10/23 8AM" name="palsrecertcoursedate" /><label> 10/23 8AM</label><br/>
             </td>  
                                                    <tr>

                </table>
                <div id="captcha-area" style="margin-left: 130px;">
                <?php
                require_once('recaptchalib.php');
                $publickey = "edited out for example";
                $privatekey = "edited out for example";
                # the response from reCAPTCHA
                $resp = null;
                # the error code from reCAPTCHA, if any
                $error = null;
                # are we submitting the page?
                if ($_POST["submit"]) {
                  $resp = recaptcha_check_answer ($privatekey,
                                                  $_SERVER["REMOTE_ADDR"],
                                                  $_POST["recaptcha_challenge_field"],
                                                  $_POST["recaptcha_response_field"]);
                  if ($resp->is_valid) {
                    echo "You got it!";
                    # in a real application, you should send an email, create an account, etc
                  } else {
                    # set the error code so that we can display it. You could also use
                    # die ("reCAPTCHA failed"), but using the error message is
                    # more user friendly
                    $error = $resp->error;
                  }
                }
                echo recaptcha_get_html($publickey, $error);
                ?>
                </div>
                <input type="submit" name="submit" value="Submit" class="submit-button" />
            </form>

这里是contactenengine .php:

<?php
require_once('recaptchalib.php');
$privatekey = "key removed intentionally for example";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}
$EmailFrom = "email@address.com";
$EmailTo = "email@address.com";
$Subject = "Refresher Form Submission";
$Name = Trim(stripslashes($_POST['Name'])); 
$EMT = Trim(stripslashes($_POST['EMT'])); 
$NREMT = Trim(stripslashes($_POST['NREMT'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Phone = Trim(stripslashes($_POST['Phone'])); 
$Address = Trim(stripslashes($_POST['Address'])); 
$Program = Trim(stripslashes($_POST['Program'])); 
$nccrtraining = Trim(stripslashes($_POST['NCCR Training'])); 
$Operating = Trim(stripslashes($_POST['Operating']));
$emt20hournccpcoursedate = Trim(stripslashes($_POST['EMT 20 Hour NCCP Course Date:']));  
$paramedic30hournccpcoursedate = Trim(stripslashes($_POST['Paramedic 30 Hour NCCP Course Date']));  
$aclsinitialcoursedate = Trim(stripslashes($_POST['ACLS Initial Course Date']));  
$aclsrecertcoursedate = Trim(stripslashes($_POST['ACLS Recert Course Date']));  
$palsinitialcoursedate = Trim(stripslashes($_POST['PALS Initial Course Date']));  
$palsrecertcoursedate = Trim(stripslashes($_POST['2015 PALS Recert Course Dates:']));  
// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
  exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "'n";
$Body .= "EMT: ";
$Body .= $EMT;
$Body .= "'n";
$Body .= "NREMT: ";
$Body .= $NREMT;
$Body .= "'n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "'n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "'n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "'n";
$Body .= "Program: ";
$Body .= $Program;
$Body .= "'n";
$Body .= "NCCR Training: ";
$Body .= $nccrtraining;
$Body .= "'n";
$Body .= "Operating: ";
$Body .= $Operating;
$Body .= "'n";
$Body .= "EMT 20 Hour NCCP Course Date: ";
$Body .= $emt20hournccpcoursedate;
$Body .= "'n";
$Body .= "Paramedic 30 Hour NCCP Course Date: ";
$Body .= $paramedic30hournccpcoursedate;
$Body .= "'n";
$Body .= "ACLS Initial Course Date: ";
$Body .= $aclsinitialcoursedate;
$Body .= "'n";
$Body .= "ACLS Recert Course Date: ";
$Body .= $aclsrecertcoursedate;
$Body .= "'n";
$Body .= "PALS Initial Course Date: ";
$Body .= $palsinitialcoursedate;
$Body .= "'n";
$Body .= "2015 PALS Recert Course Dates: ";
$Body .= $palsrecertlcoursedate;
$Body .= "'n";
// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page 
if ($success){
  print "<meta http-equiv='"refresh'" content='"0;URL=payment.html'">";
}
else{
  print "<meta http-equiv='"refresh'" content='"0;URL=error.htm'">";
}
?>

在我这边,当我填写表格时,我收到以下电子邮件:

Name: Firstname Lastname
EMT: 12345
NREMT: 123456
Email: email@address.com
Phone: 5555555555
Address: Full address
Program: EMT NCCR
NCCR Training:
Operating: Windows
EMT 20 Hour NCCP Course Date:
Paramedic 30 Hour NCCP Course Date:
ACLS Initial Course Date:
ACLS Recert Course Date:
PALS Initial Course Date:
2015 PALS Recert Course Dates:

NCCR培训、EMT 20小时NCCP课程日期、护理人员30小时NCCP课程日期、ACLS初始课程日期、ACLS最近课程日期、PALS初始课程日期和2015 PALS最近课程日期等字段完全空白。但其他领域都很好。据我所知,所有字段都以相同的方式配置。

想法吗?谢谢你,Stackoverflow。

因为您没有针对正确的属性。您需要使用每个表单元素的name属性,例如,$_POST['NCCR Training'])是错误的,应该是$_POST['nccrtraining'])

您在收集帖子数据中缺少添加的名称,请尝试更改,

$_POST['NCCR Training'] to $_POST['nccrtraining']
$_POST['EMT 20 Hour NCCP Course Date'] to $_POST['emt20hournccpcoursedate']
$_POST['Paramedic 30 Hour NCCP Course '] to _POST['paramedic30hournccpcoursedate']
$_POST['ACLS Initial Course Date'] to $_POST['aclsinitialcoursedate']
$_POST['ACLS Initial Course Date'] to $_POST['aclsrecertcoursedate']
$_POST['PALS Initial Course Date'] to $_POST['palsinitialcoursedate']