CGI Error when sending php mail

Hi all,
I created this page to send all my professors’ email. When I send the email I get this error.

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.
Code:
if (isset($_POST['sendmail'])) {
    //echo "<pre>";
    //print_r($_POST);
    //echo "</pre>";
    
    ini_set('sendmail_from','[email protected]');
    $FromWho = "Sys Admin <[email protected]>";
    
    $mailBody = $_POST['emailBody'];
    $emailTo = $_POST['toEmail'];
    $ccTo = $_POST['ccTo'];
    $subject = $_POST['subject'];
    $count = 0;
    
    if ($emailTo == "all") {
    
    
    $nameConcat = "";
    
        do {
        
        $nameConcat = $row_getEmails['FirstName']." ".$row_getEmails['LastName'];
        $priEmail = $nameConcat." <".$row_getEmails['Email1'].">";
        $secEmail = $row_getEmails['Email2'];
        
        $eachBody = $mailBody;
        $eachBody = str_replace("%Fullname%",$nameConcat,$eachBody);
        $eachBody = str_replace("%SecondaryEmail%",$row_getEmails['Email2'],$eachBody);
        
               
        if (!mail($priEmail, $subject, $eachBody, "From: $FromWho")) {
            echo "Error sending email";
            
            }            
            echo "Success!";
        
    
        $count++;                 
        
        } while ($row_getEmails = mysql_fetch_assoc($getEmails));
        
        
    }
        
    
    
}
?>

Someone please help me if I am going wrong. Need this urgently.

Thanks,
Sid