I have a form where I only want certain information to be emailed to an account depending on their selection from a select tag in the form.
Here is my HTML of the select tag:
<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>
Here is my PHP that I'm having the issue with:
<?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 . "
Plan Table: " . $smallplantable . "
C5035: " . $smallcopierone . "
C5045: " . $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 . "
Trailer(s) or Similar Sized Office(s): " . $mediumtrailers . "
Plan Table(s): " . $mediumplantable . "
External Wifi: " . $wifi . "
C5035: " . $mediumcopierone . "
C5045: " . $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 . "
Trailer(s) or Similar Sized Office(s): " . $largetrailers . "
Plan Table(s): " . $largeplantable . "
External Wifi: " . $largewifi . "
C5035: " . $largecopierone . "
C5045: " . $smallcopiertwo;
$headers = 'From:' . $primaryemail;
mail($to, $subject, $body, $headers);
}
}
The code works fine with just the one if statement to check make sure primaryemail is not empty. However, when I added the else if statements to change what is sent based on what is selected in the numberofstaff id it fails to work.
Any help is appreciated. I don't see why this wouldn't be possible.