【发布时间】:2015-07-07 15:35:55
【问题描述】:
我有一个表格,我只希望某些信息通过电子邮件发送到帐户,具体取决于他们从表格中的选择标签中进行的选择。
这是我的选择标签的 HTML:
<select id="numberofstaff">
<option class="staffselection" value="">--Select--</option>
<option class="staffselection" value="smalljobsite">1-3 staff</option>
<option class="staffselection" value="mediumjobsite">4-7 staff</option>
<option class="staffselection" value="largejobsite">8+ staff</option>
</select>
这是我遇到问题的 PHP:
<?php
if (isset($_POST['primaryemail']) && isset($_POST['numberofstaff'])){
$numberofstaff = $_POST['numberofstaff'];
$smallplantable = $_POST['smallplantable'];
$smallcopierone = $_POST['smallcopierone'];
$smallcopiertwo = $_POST['smallcopiertwo'];
$mediumtrailers = $_POST['mediumtrailers'];
$mediumplantable = $_POST['mediumplantable'];
$wifi = $_POST['wifi'];
$mediumcopierone = $_POST['mediumcopierone'];
$mediumcopiertwo = $_POST['mediumcopiertwo'];
$largetrailers = $_POST['largetrailers'];
$largeplantable = $_POST['largeplantable'];
$largewifi = $_POST['largewifi'];
$largecopierone = $_POST['largecopierone'];
$largecopiertwo = $_POST['largecopiertwo'];
$numberofstaff = $_POST['numberofstaff'];
$smallplantable= $_POST['smallplantable'];
$smallcopierone= $_POST['smallcopierone'];
$smallcopiertwo= $_POST['smallcopiertwo'];
$mediumtrailers= $_POST['mediumtrailers'];
$mediumplantable= $_POST['mediumplantable'];
$wifi= $_POST['wifi'];
$mediumcopierone= $_POST['mediumcopierone'];
$mediumcopiertwo= $_POST['mediumcopiertwo'];
$largetrailers= $_POST['largetrailers'];
$largeplantable= $_POST['largeplantable'];
$largewifi= $_POST['largewifi'];
$largecopierone= $_POST['largecopierone'];
$largecopiertwo= $_POST['largecoipertwo'];
if (!empty($primaryemail) && $numberofstaff == 'smalljobsite') {
$to = 'testemail@test.com';
$subject = 'Jobsite Form Submitted';
$body = Number of Users: " . $numberofstaff . "\r\nPlan Table: " . $smallplantable . "\r\nC5035: " . $smallcopierone . "\r\nC5045: " . $smallcopiertwo;
$headers = 'From:' . $primaryemail;
mail($to, $subject, $body, $headers);
}
else if (!empty($primaryemail) && $numberofstaff == 'mediumjobsite') {
$to = testemail@test.com';
$subject = 'Jobsite Form Submitted';
$body = "Number of Users: " . $numberofstaff . "\r\nTrailer(s) or Similar Sized Office(s): " . $mediumtrailers . "\r\nPlan Table(s): " . $mediumplantable . "\r\nExternal Wifi: " . $wifi . "\r\nC5035: " . $mediumcopierone . "\r\nC5045: " . $mediumcopiertwo;
$headers = 'From:' . $primaryemail;
mail($to, $subject, $body, $headers);
}
else if (!empty($primaryemail) && $numberofstaff == 'largejobsite') {
$to = 'testemail@test.com';
$subject = 'Jobsite Form Submitted';
$body = "Number of Users: " . $numberofstaff . "\r\nTrailer(s) or Similar Sized Office(s): " . $largetrailers . "\r\nPlan Table(s): " . $largeplantable . "\r\nExternal Wifi: " . $largewifi . "\r\nC5035: " . $largecopierone . "\r\nC5045: " . $smallcopiertwo;
$headers = 'From:' . $primaryemail;
mail($to, $subject, $body, $headers);
}
}
该代码仅使用一个 if 语句即可正常工作,以检查确保 primaryemail 不为空。但是,当我添加 else if 语句以根据 numberofstaff id 中选择的内容更改发送的内容时,它无法工作。
感谢任何帮助。我不明白为什么这是不可能的。
【问题讨论】:
-
是语法错误吗? $body = 用户数:" . $numberofstaff 应该是 $body = "用户数:" . $numberofstaff