Your code is littered with extra empty else statements....try to make your code easier to read, it makes it easier for people to want to help....
Looks like you may have figured out your problem....
No changes to your original code other than cosmetic
<?php
$staffQuery = mysqli_query($staffConnected, "SELECT `name`, `email`, `department`, `position` FROM `staff` WHERE `class`=2 ORDER BY `department`, `name` ASC")
if($staffQuery){
$rowNum=1;
$cellNum=0;
$amountOfStaffReturned=mysqli_num_rows($staffQuery);
if($amountOfStaffReturned>0){
$departmentHeader=false;
$content.='<div class="emailHeader">Staff Contacts</div>';
while($staff=mysqli_fetch_array($staffQuery, MYSQLI_ASSOC)) {
$staffName=$staff['name']; $staffEmail=$staff['email']; $staffDepartment=$staff['department']; $staffPosition=$staff['position'];
$rowName=rowName($rowNum);
if($rowNum>1){
$rowEmailClassAdd=' emailRow';
} else {
$rowEmailClassAdd='';
}
if($cellNum%2==0){
if($departmentHeader!=$staffDepartment) {
$content.='<div class="departmentHeader">'.$staffDepartment.'</div>'; $departmentHeader=$staffDepartment;
}
if($cellNum != 0){
$content.='</div>';
}
$content.='<div class="overflowclear'.$rowEmailClassAdd.'" id="emailStaff'.ucfirst($rowName).'Row">';
$rowNum++;
}
$content .='<div class="emailCell">
<div class="emailTitle">'.$staffName.'</div>
<div class="emailSubTitle">'.$staffPosition.'</div>
<div><a class="contactemail" href="mailto:'.$staffEmail.'">'.escapeemail($staffEmail).'</a></div>
</div>';
if($amountOfStaffReturned%2 != 0 && $cellNum+1 == $amountOfStaffReturned) {
$content.='<div class="emailCell">
</div>
</div>';
}
$cellNum++;
} //end while
}
}