title: Generate csv file from form data on fly then email to address
body: <p>I have a form that users are able to fill in and want to be able to generate an Excel file and populate it with the data from the form. I then want it to email me the file with the completed data. How can this be done?</p>
  
  <p>This is currently generating the email:</p>
  
  <pre><code>    $body = "You have a new member account application from the website, please see the details below:
  
  \n
  Membership Type: $group1_field\n\n
  
  Contact Details\n
  Organisation: $member_organ_field\n
  Address: $member_address_field\n
  Postcode: $member_post_field\n
  Tel: $member_tel_field\n
  Fax: $member_fax_field\n
  Email address: $member_email_field\n
  Website: $member_website_field\n\n
  Contacts \n
  Member 1 \n
  Name: $member1_name1_field\n
  Position: $member1_position1_field\n
  Direct Email: $member1_email1_field\n
  Direct Tel: $member1_tel1_field\n\n
  Member 2 \n
  Name: $member1_name2_field\n
  Position: $member1_position2_field\n
  Direct Email: $member1_email2_field\n\n
  Member 3 \n
  Name: $member1_name3_field\n
  Position: $member1_position3_field\n
  Direct Email: $member1_email3_field\n\n
  Type Of Organisation: ".$checkbox1results."\n
  Type Of Activity: ".$checkbox2results."$member3_other_field\n\n
  Summary Description \n
  $member_summary_field \n\n
  Company Information \n
  Total no. of employees (Welsh site): $member4_total_field\n
  Turnover (from Welsh site): $member4_turnover_field\n
  Date of company formation: $member4__formation\n
  Do you export aborad? Where? $member4_export_field\n\n
  Member consent: ".$checkbox3results."\n\n
  Completed by: $member4_com_field\n
  Company position: $member4_com_pos_field\n
  Invoice required: $CheckboxGroup4_field\n\n
  
  Please follow up this request asap.\n\n
  ";
  
  mail($to, $subject, $body);
  
  echo "Thank you for your account application, we will contact you shortly.";
  
  } ?&gt;
  </code></pre>