How to mail .xls using PHP

I have created an application form that outputs data into an e-mail as well as submitting a receipt to the user who fills out the application form. What I need is PHP to take the data that was input into the application form and write out the data into a spreadsheet (.xls) file format. Can anyone help me out? I understand my code needs to be cleaned up, needs secure injection functions and formatted, but I need it to work first and foremost. Here is the code:

$to = ‘[email protected]’ ; //put your email address on which you want to receive the information
$subject = ‘WASD Application Data’; //set the subject of email.
$subject2 = ‘Your West Anglophone School District Application Receipt’;
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$message = “

Application Date: ”.$_POST[‘DateofApplication’]."
Student Type: ".$_POST[‘student_type’]."
Family Name: ".$_POST[‘FamilyName’]."
First Name: ".$_POST[‘FirstName’]."
Gender: ".$_POST[‘gender’]."
Birth Date: ".$_POST[‘DateofBirth’]."
English Name: ".$_POST[‘CdnName’]."
Passport #: ".$_POST[‘PassportNum’]."
Passport Exp: ".$_POST[‘PassportExp’]."
Father’s Name: ".$_POST[‘Father’]."
Mother’s Name: ".$_POST[‘Mother’]."
Parents w/ student: ".$_POST[‘parents_living_with_student’]."
Home Street: ".$_POST[‘HomeStreet’]."
Home City: ".$_POST[‘HomeCommunity’]."
Home Province: ".$_POST[‘HomeProvince’]."
Home Country: ".$_POST[‘HomeCountry’]."
Home Postal Zip: ".$_POST[‘HomePostalZip’]."
Home Telephone: ".$_POST[‘HomeTelephone’]."
Home Fax: ".$_POST[‘HomeFax’]."
Home EMail: ".$_POST[‘HomeEMail’]."
Arrival Date: ".$_POST[‘ArrivalDate’]."
Departure Date: ".$_POST[‘DepartureDate’]."
School Year: ".$_POST[‘SchoolYear’]."
School First: ".$_POST[‘SchoolFirst’]."
School Second: ".$_POST[‘SchoolSecond’]."
Semester Request: ".$_POST[‘semester_request’]."
English Skill: ".$_POST[‘Language’]."
Language Assistance: ".$_POST[‘LanguageAssistance’]."
Custodian: ".$_POST[‘Custodian’]."
Custodian Street: ".$_POST[‘CustodianStreet’]."
Custodian Community: ".$_POST[‘CustodianCommunity’]."
Country: ".$_POST[‘CustodianCountry’]."
Custodian Zip: ".$_POST[‘CustodianPostalZip’]."
Custodian Telephone: ".$_POST[‘CustodianTelephone’]."
Custodian Fax: ".$_POST[‘CustodianFax’]."
Custodian EMail: ".$_POST[‘CustodianEMail’]."
Broker Agency: ".$_POST[‘BrokerAgent’]."
Agent Contact: ".$_POST[‘Contact’]."
Broker Agent Street: ".$_POST[‘BrokerAgentStreet’]."
Broker Agent City: ".$_POST[‘BrokerAgentCommunity’]."
Broker Agent Country: ".$_POST[‘BrokerAgentCountry’]."
BrokerAgent Postal: ".$_POST[‘BrokerAgentPostalZip’]."
Broker Agent Telephone: ".$_POST[‘BrokerAgentTelephone’]."
Broker Agent Fax: ".$_POST[‘BrokerAgentFax’]."
Broker Agent EMail: ".$_POST[‘BrokerAgentEMail’]."
Primary Contact: ".$_POST[‘primary_contact’]."
Good Health: ".$_POST[‘good_health’]."
Bad Health Reason: ".$_POST[‘bad_health_reason’]."
Allergies: ".$_POST[‘allergies’]."
Special Needs: ".$_POST[‘SpecialNeeds’]."
Disability Support Reason: ".$_POST[‘disability_support_reason’]."
Primary Contact: ".$_POST[‘primary_contact’]."
" ;
$from = “West Anglophone School District”;
mail($to, $subject, $message, $headers);
header(‘Location: application_final.html’);

$email_from = $_POST[‘HomeEMail’];
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
$headers = “From:” . $from;
$headers2 = 'From: '.$to."\r\n".
‘X-Mailer: PHP/’ . phpversion();

$replymsg = "Thank you for your interest in Anglophone West School District, Fredericton, NB, Canada.

Your application has been successfully submitted.

Please remember to submit in PDF format the supporting documents to [email protected] :

  1. Proof Of Age (First page of your passport)
  2. A transcript of marks from last school attended (translated into English)
  3. A notarized attendance agreement
    mail($email_from, $subject2, $replymsg, $headers2);

Thank you!

Sponsor our Newsletter | Privacy Policy | Terms of Service