php - Form emailing on browser load -
the form have created below emails input data in csv file. problem having every time browser loads page sends blank version of csv file, , once form submitted want redirect "thank you" page. how can accomplish this?
the php use before 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 boundary string $semi_rand = md5(time()); $mime_boundary = "==multipart_boundary_x{$semi_rand}x"; //add headers 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 multipart boundary above plain message $message = "this 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 $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); } ?>
your line @ top, checks see if page form submit, not expand entire function.
you have:
if(isset($_post['formsubmit'])) { }
however closing bracket } should way @ bottom, right before ?>. stands now, code doing check see if there form submit, , if it's executing nothing, since there no code within brackets. after completed automatically begins running through of other code, regardless if form submit or not.
if you're wanting page redirect, place below code right before newly moved closing bracket:
header('location: http://www.yoursite.com/new_page.php');
Comments
Post a Comment