The form I have created below emails the input data in a CSV file. The problem I am having is every time the browser loads the page it sends a blank version of the CSV file, and once the form is submitted I want it to redirect to a "thank you" page. How can I accomplish this?
The PHP I use before the HTML form is:
<?php
if(isset($_POST['formSubmit'])) {
}
$email=$_REQUEST['email'];
$firstName=$_REQUEST['firstName'];
$lastName=$_REQUEST['lastName'];
$to = "Ali@ebig.co.uk";
$subject = "New application submission";
$message = "".
"Email: $email" . "\n" .
"First Name: $firstName" . "\n" .
"Last Name: $lastName";
//The Attachment
$varTitle = $_POST['formTitle'];
$varForname = $_POST['formForname'];
$varMiddlename = $_POST['formMiddlename'];
$varSurname = $_POST['formSurname'];
$varKnownas = $_POST['formKnownas'];
$varAdressline1 = $_POST['formAdressline1'];
$varAdressline2 = $_POST['formAdressline2'];
$varAdressline3 = $_POST['formAdressline3'];
$varAdressline4 = $_POST['formAdressline4'];
$varAdressline5 = $_POST['formAdressline5'];
$varPostcode = $_POST['formPostcode'];
$varTelephone = $_POST['formTelephone'];
$varMobile = $_POST['formMobile'];
$varEmail = $_POST['formEmail'];
$varApproval = $_POST['formApproval'];
$varothersurname = $_POST['formothersurname'];
$varsex = $_POST['formsex'];
$varninumber = $_POST['formninumber'];
$varjobtitle = $_POST['formjobtitle'];
$vardates = $_POST['formdates'];
$varresponsibilities = $_POST['formresponsibilities'];
$varjobtitle2 = $_POST['formjobtitle2'];
$vardates2 = $_POST['formdates2'];
$varresponsibilities2 = $_POST['formresponsibilities2'];
$varjobtitle3 = $_POST['formjobtitle3'];
$vardates3 = $_POST['formdates3'];
$varresponsibilities3 = $_POST['formresponsibilities3'];
$varwebsite = $_POST['formwebsite'];
$vartshirt = $_POST['formtshirt'];
$vardietary = $_POST['formdietary'];
$varpc = $_POST['formpc'];
$varmac = $_POST['formmac'];
$varlaptop = $_POST['formlaptop'];
$vardongle = $_POST['formdongle'];
$varediting = $_POST['formediting'];
$varsocial = $_POST['formsocial'];
$varphotography = $_POST['formphotography'];
$varfilming = $_POST['formfilming'];
$vartraining = $_POST['formtraining'];
$varexhibition = $_POST['formexhibition'];
$varspecial = $_POST['formspecial'];
$varhobbies = $_POST['formhobbies'];
$varphotography = $_POST['formphotography'];
$varfilming = $_POST['formfilming'];
$vartraining = $_POST['formtraining'];
$varexcel = $_POST['formexcel'];
$varbigpicture = $_POST['formbigpicture'];
$varcriminal = $_POST['formcriminal'];
$cr = "\n";
$data = "$varTitle" . ',' . "$varForname" . ',' . "$varMiddlename" . ',\\other variables.
$attachments[] = Array(
'data' => $data,
'name' => 'application.csv',
'type' => 'application/vnd.ms-excel'
);
//Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//Add the headers for a file attachment
$headers = "MIME-Version: 1.0\n" .
"From: {$from}\n" .
"Cc: davidkirrage@gmail.com\n".
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
//Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$text . "\n\n";
//Add sttachments
foreach($attachments as $attachment){
$data = chunk_split(base64_encode($attachment['data']));
$name = $attachment['name'];
$type = $attachment['type'];
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" ;
$message .= "--{$mime_boundary}--\n";
mail($to, $subject, $message, $headers);
}
?>