How to drop empty responses in an array of fields?

Check whether the field is empty before adding it to the mail.

foreach($fields as $a => $b) {
    if (!empty($_REQUEST[$a])) {
        $body .= sprintf("%20s:%s\n",$b,$_REQUEST[$a]);
    }
}

Leave a Comment