I've got a PHP script to take answers from a referral form and send it by email to my client (below). The client has now asked that only questions that have been answered be sent to them. How can I strip out the fields that are empty from the email?
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data-Medical Referral";
$fields = array();
$fields{"referrer"} = "Referral Source";
$fields{"referraldate"} = "Date of Referral";
$fields{"filenumber"} = "File Number";
$fields{"hearingdate"} = "Hearing Date";
$fields{"legalfirm"} = "Legal Firm";
$fields{"Address"} = "Legal Firm Address";
$fields{"plantiffattorney"} = "Plantiff Attorney";
$fields{"plantiffaddress"} = "Plantiff Attorney Address";
$fields{"plantifftelephone"} = "Plantiff Attorney Telephone";
$fields{"plantiffemail"} = "Plantiff Attorney Email";
$fields{"defenceattorney"} = "Defence Attorney";
$fields{"defenceaddress"} = "Defence Attorney Address";
$fields{"defencetelephone"} = "Defence Attorney Telephone";
$fields{"defenceemail"} = "Defence Attorney Email";
$fields{"lawclerk"} = "Legal Assistant/Law Clerk";
$fields{"lawclerktelephone"} = "Legal Assistant/Law Clerk Telephone";
$fields{"lawclerkemail"} = "Legal Assistant/Law Clerk Email";
$fields{"insurancecompany"} = "Name of Insurance Company";
$fields{"insuranceaddress"} = "Insurance Company Address";
$fields{"Adjuster"} = "Adjuster Name";
$fields{"adjusternumber"} = "Adjuster Telephone";
$fields{"adjusterfax"} = "Adjuster Fax";
$fields{"adjusteremail"} = "Adjuster Email";
$fields{"claimnumber"} = "Claim Number";
$fields{"claimantname"} = "Claimant Name";
$fields{"gender"} = "Gender";
$fields{"dateofbirth"} = "Date of Birth";
$fields{"claimantaddress"} = "Claimant Address";
$fields{"claimantcity"} = "Claimant City";
$fields{"claimantpostal"} = "Claimant Postal Code";
$fields{"claimanttelephone"} = "Claimant Telephone";
$fields{"lossdate"} = "Date of Loss";
$fields{"Injuries"} = "Injuries";
$fields{"Diagnosis"} = "Diagnosis";
$fields{"reportaddress"} = "Report to Address";
$fields{"transportation"} = "Transportation Required";
$fields{"translation"} = "Translation Required";
$fields{"language"} = "Language";
$fields{"abilitiesevaluation"} = "Abilities Evaluation";
$fields{"occupationaltherapist"} = "Legal IME-Occupational Therapist";
$fields{"rheumatologist"} = "Legal IME-Rheumatologist";
$fields{"chiropractic"} = "Legal IME-Chiropractic";
$fields{"opthamologist"} = "Legal IME-Opthamologist";
$fields{"socialworker"} = "Legal IME-Social Worker";
$fields{"dental"} = "Legal IME-Dental";
$fields{"optomertrist"} = "Legal IME-Optometrist";
$fields{"slp"} = "Legal IME-SLP";
$fields{"endocrinologist"} = "Legal IME-Endocrinologist";
$fields{"orthopedic"} = "Legal IME-Orthopedic Surgeon";
$fields{"tsa"} = "Legal IME-TSA";
$fields{"ent"} = "Legal IME-ENT";
$fields{"pediatrician"} = "Legal IME-Pediatrician";
$fields{"vascularsurgeon"} = "Legal IME-Vascular Surgeon";
$fields{"gastroenterologist"} = "Legal IME-Gastroenterologist";
$fields{"physician"} = "Legal IME-Physician";
$fields{"vocationalevaluation"} = "Legal IME-Vocational Evaluation";
$fields{"internalmedicine"} = "Legal IME-Internal Medicine";
$fields{"physiatrist"} = "Legal IME-Physiatrist";
$fields{"legalfilereview"} = "Legal File Review";
$fields{"jobanalysis"} = "Legal IME-Job Analysis/WSA";
$fields{"physiotherapist"} = "Legal IME-Physiotherapist";
$fields{"lifecare"} = "Life Care Plan";
$fields{"neurologist"} = "Legal IME-Neurologist";
$fields{"psychiatrist"} = "Legal IME-Psychiatrist";
$fields{"lifecarereview"} = "Life Care Plan Review";
$fields{"neuropsychologist"} = "Legal IME-Neuropsychologist";
$fields{"psychologist"} = "Legal IME-Psychologist";
$fields{"other"} = "Other";
$fields{"otherrequired"} = "Service";
$fields{"neurosurgeon"} = "Legal IME-Neurosurgeon";
$fields{"psychovocational"} = "Legal IME-Pyschovocational";
$fields{"comments"} = "Comments";
$body="Referral Info:
";
foreach($fields as $a => $b) {
$body .= sprintf("%20s:%s
",$b,$_REQUEST[$a]);
}
if(empty($fields)) {
echo 'Please fill in the submission form';
return false;
}
$send = mail($email, $subject, $body);
if ($send){
print "Thank you!";
}else{
print "Oops!";
}