cdm30 Posted May 20, 2011 Share Posted May 20, 2011 Hi, I searched and couldn't find a previous solution.. I'm supposed to take this existing long form and tweak it so it excludes empty fields when emailed.. Can anyone show me what would work for this code below? Any help would be greatly appreciated.. Sorry for the long code, i didn't know where to cut it off.. <?php $EmailTo = Trim(stripslashes($_POST['EmailTo'])); $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $Subject = ""; // terms $terms_conditions_details = Trim(stripslashes($_POST['terms_conditions_details'])); // contact information $full_name = Trim(stripslashes($_POST['full_name'])); $title = Trim(stripslashes($_POST['title'])); $company = Trim(stripslashes($_POST['company'])); $billing_address = Trim(stripslashes($_POST['billing_address'])); $billing_city = Trim(stripslashes($_POST['billing_city'])); $billing_state = Trim(stripslashes($_POST['billing_state'])); $billing_zip = Trim(stripslashes($_POST['billing_zip'])); $phone = Trim(stripslashes($_POST['phone'])); $alt_phone = Trim(stripslashes($_POST['alt_phone'])); $how_did_you_hear = Trim(stripslashes($_POST['how_did_you_hear'])); // event information $event_date = Trim(stripslashes($_POST['event_date'])); $guests = Trim(stripslashes($_POST['guests'])); $event_start_time = Trim(stripslashes($_POST['event_start_time'])); $event_end_time = Trim(stripslashes($_POST['event_end_time'])); $event_address = Trim(stripslashes($_POST['event_address'])); $event_city = Trim(stripslashes($_POST['event_city'])); $event_state = Trim(stripslashes($_POST['event_state'])); $event_zip = Trim(stripslashes($_POST['event_zip'])); $event_type = Trim(stripslashes($_POST['event_type'])); $event_type_other = Trim(stripslashes($_POST['event_type_other'])); $event_theme = Trim(stripslashes($_POST['event_theme'])); $special_requests = Trim(stripslashes($_POST['special_requests'])); $budget = Trim(stripslashes($_POST['budget'])); $service_type = Trim(stripslashes($_POST['service_type'])); // wings & wingers $grilled_wings = Trim(stripslashes($_POST['grilled_wings'])); $buffalo_wings = Trim(stripslashes($_POST['buffalo_wings'])); $wingers = Trim(stripslashes($_POST['wingers'])); $wing_sauces1 = Trim(stripslashes($_POST['wing_sauces1'])); $wing_sauces2 = Trim(stripslashes($_POST['wing_sauces2'])); $wing_sauces3 = Trim(stripslashes($_POST['wing_sauces3'])); $wing_sauces4 = Trim(stripslashes($_POST['wing_sauces4'])); $wing_sauces5 = Trim(stripslashes($_POST['wing_sauces5'])); $wing_sauces6 = Trim(stripslashes($_POST['wing_sauces6'])); $wing_sauces7 = Trim(stripslashes($_POST['wing_sauces7'])); $wing_sauces8 = Trim(stripslashes($_POST['wing_sauces8'])); $wing_sauces9 = Trim(stripslashes($_POST['wing_sauces9'])); $wing_sauces10 = Trim(stripslashes($_POST['wing_sauces10'])); $wing_sauces11 = Trim(stripslashes($_POST['wing_sauces11'])); $wing_sauces12 = Trim(stripslashes($_POST['wing_sauces12'])); $wing_sauces13 = Trim(stripslashes($_POST['wing_sauces13'])); $wing_sauces14 = Trim(stripslashes($_POST['wing_sauces14'])); // party platters $chicken_finger_platter = Trim(stripslashes($_POST['chicken_finger_platter'])); $chicken_nugget_platter = Trim(stripslashes($_POST['chicken_nugget_platter'])); $chicken_wing_platter = Trim(stripslashes($_POST['chicken_wing_platter'])); // salads $caesar_salad = Trim(stripslashes($_POST['caesar_salad'])); $house_salad = Trim(stripslashes($_POST['house_salad'])); $cobb_salad = Trim(stripslashes($_POST['cobb_salad'])); $sea_breeze_salad = Trim(stripslashes($_POST['sea_breeze_salad'])); // appetizers $fresh_fruit_platter = Trim(stripslashes($_POST['fresh_fruit_platter'])); $chilled_vegetable_platter = Trim(stripslashes($_POST['chilled_vegetable_platter'])); $cocktail_shrimp = Trim(stripslashes($_POST['cocktail_shrimp'])); $tailgate_chips_platter = Trim(stripslashes($_POST['tailgate_chips_platter'])); $chips_and_salsa = Trim(stripslashes($_POST['chips_and_salsa'])); $spinach_artichoke_dip_platter = Trim(stripslashes($_POST['spinach_artichoke_dip_platter'])); $quesadilla_platter = Trim(stripslashes($_POST['quesadilla_platter'])); // entrees $bbq_ribs_platter = Trim(stripslashes($_POST['bbq_ribs_platter'])); $hawaiian_chicken = Trim(stripslashes($_POST['hawaiian_chicken'])); $mahi_over_rice = Trim(stripslashes($_POST['mahi_over_rice'])); // sandwiches $gourmet_slider_platter = Trim(stripslashes($_POST['gourmet_slider_platter'])); $mini_cheeseburger_platter = Trim(stripslashes($_POST['mini_cheeseburger_platter'])); $club_sandwich_platter = Trim(stripslashes($_POST['club_sandwich_platter'])); $turkey_wrap_platter = Trim(stripslashes($_POST['turkey_wrap_platter'])); $philly_cheese_platter = Trim(stripslashes($_POST['philly_cheese_platter'])); // dessert $chocolate_brownie_platter = Trim(stripslashes($_POST['chocolate_brownie_platter'])); $apple_crisp = Trim(stripslashes($_POST['apple_crisp'])); $mini_gourmet_cheesecakes = Trim(stripslashes($_POST['mini_gourmet_cheesecakes'])); //$10 meal deal $meal_deal_wings = Trim(stripslashes($_POST['meal_deal_wings'])); $meal_deal_grilled_chicken = Trim(stripslashes($_POST['meal_deal_grilled_chicken'])); $meal_deal_burger = Trim(stripslashes($_POST['meal_deal_burger'])); $meal_deal_lemonade = Trim(stripslashes($_POST['meal_deal_lemonade'])); $meal_deal_iced_tea = Trim(stripslashes($_POST['meal_deal_iced_tea'])); $meal_deal_sauces1 = Trim(stripslashes($_POST['meal_deal_sauces1'])); $meal_deal_sauces2 = Trim(stripslashes($_POST['meal_deal_sauces2'])); $meal_deal_sauces3 = Trim(stripslashes($_POST['meal_deal_sauces3'])); $meal_deal_sauces4 = Trim(stripslashes($_POST['meal_deal_sauces4'])); $meal_deal_sauces5 = Trim(stripslashes($_POST['meal_deal_sauces5'])); $meal_deal_sauces6 = Trim(stripslashes($_POST['meal_deal_sauces6'])); $meal_deal_sauces7 = Trim(stripslashes($_POST['meal_deal_sauces7'])); $meal_deal_sauces8 = Trim(stripslashes($_POST['meal_deal_sauces8'])); $meal_deal_sauces9 = Trim(stripslashes($_POST['meal_deal_sauces9'])); $meal_deal_sauces10 = Trim(stripslashes($_POST['meal_deal_sauces10'])); $meal_deal_sauces11 = Trim(stripslashes($_POST['meal_deal_sauces11'])); $meal_deal_sauces12 = Trim(stripslashes($_POST['meal_deal_sauces12'])); $meal_deal_sauces13 = Trim(stripslashes($_POST['meal_deal_sauces13'])); $meal_deal_sauces14 = Trim(stripslashes($_POST['meal_deal_sauces14'])); // box lunches $box_turkey_ruben = Trim(stripslashes($_POST['box_turkey_ruben'])); $box_blt_on_ciabatta = Trim(stripslashes($_POST['box_blt_on_ciabatta'])); $box_club = Trim(stripslashes($_POST['box_club'])); $box_ham_and_cheese = Trim(stripslashes($_POST['box_ham_and_cheese'])); $box_chipolte_shrimp_blt = Trim(stripslashes($_POST['box_chipolte_shrimp_blt'])); $box_turkey_bacon_ranch = Trim(stripslashes($_POST['box_turkey_bacon_ranch'])); $box_buffalo_chicken = Trim(stripslashes($_POST['box_buffalo_chicken'])); $box_veggie = Trim(stripslashes($_POST['box_veggie'])); $box_caesar_salad = Trim(stripslashes($_POST['box_caesar_salad'])); $box_house_salad = Trim(stripslashes($_POST['box_house_salad'])); $box_cobb_salad = Trim(stripslashes($_POST['box_cobb_salad'])); $box_sea_breeze_salad = Trim(stripslashes($_POST['box_sea_breeze_salad'])); // full service catering $theme_package = Trim(stripslashes($_POST['theme_package'])); $theme_package_information = Trim(stripslashes($_POST['theme_package_information'])); $reception = Trim(stripslashes($_POST['reception'])); $reception_information = Trim(stripslashes($_POST['reception_information'])); $specialty_stations = Trim(stripslashes($_POST['specialty_stations'])); $bar_beverage_service = Trim(stripslashes($_POST['bar_beverage_service'])); $bar_beverage_service_information = Trim(stripslashes($_POST['bar_beverage_service_information'])); $breakfast = Trim(stripslashes($_POST['breakfast'])); $breakfast_information = Trim(stripslashes($_POST['breakfast_information'])); $notes = Trim(stripslashes($_POST['notes'])); // payment $payment1 = Trim(stripslashes($_POST['payment1'])); $payment2 = Trim(stripslashes($_POST['payment2'])); $payment3 = Trim(stripslashes($_POST['payment3'])); $payment4 = Trim(stripslashes($_POST['payment4'])); $payment5 = Trim(stripslashes($_POST['payment5'])); $payment6 = Trim(stripslashes($_POST['payment6'])); // confirmation email $confirmation_subject = ""; $confirmation_body = "$full_name,\n\n Thank you for emailing us. A catering manager from your location will get in touch with you shortly.\n\n \n \n"; $Body = ""; $Body .= "CONTACT INFORMATION\n"; $Body .= "\nFull Name: "; $Body .= $full_name; $Body .= "\nTitle: "; $Body .= $title; $Body .= "\nCompany: "; $Body .= $company; $Body .= "\nBilling Address: "; $Body .= $billing_address; $Body .= ", "; $Body .= $billing_city; $Body .= ", "; $Body .= $billing_state; $Body .= ", "; $Body .= $billing_zip; $Body .= "\nPhone: "; $Body .= $phone; $Body .= "\nAlternate Phone: "; $Body .= $alt_phone; $Body .= "\nHow did you hear about us?: "; $Body .= $how_did_you_hear; $Body .= "\n"; $Body .= $terms_conditions_details; $Body .= "\n\nEVENT INFORMATION\n"; $Body .= "\nEvent Date: "; $Body .= $event_date; $Body .= "\nNumber of Guests: "; $Body .= $guests; $Body .= "\nEvent Start Time: "; $Body .= $event_start_time; $Body .= "\nEvent End Time: "; $Body .= $event_end_time; $Body .= "\nEvent Address: "; $Body .= $event_address; $Body .= ", "; $Body .= $event_city; $Body .= ", "; $Body .= $event_state; $Body .= ", "; $Body .= $event_zip; $Body .= "\nType of Event: "; $Body .= $event_type; $Body .= "\nType of Event: Other: "; $Body .= $event_type_other; $Body .= "\nEvent Theme: "; $Body .= $event_theme; $Body .= "\nSpecial Requests: "; $Body .= $special_requests; $Body .= "\nBudget: "; $Body .= $budget; $Body .= "\nType of Service: "; $Body .= $service_type; $Body .= "\n\nWINGS & WINGERS\n"; $Body .= "\nGrilled Wings: "; $Body .= $grilled_wings; $Body .= "\nBuffalo Wings: "; $Body .= $buffalo_wings; $Body .= "\nWingers: "; $Body .= $wingers; $Body .= "\nWing Sauces: "; $Body .= "$wing_sauces1, $wing_sauces2, $wing_sauces3, $wing_sauces4, $wing_sauces5, $wing_sauces6, $wing_sauces7, $wing_sauces8, $wing_sauces9, $wing_sauces10, $wing_sauces11, $wing_sauces12, $wing_sauces13, $wing_sauces14"; $Body .= "\n\nPARTY PLATTERS\n"; $Body .= "\nChicken Finger Platter: "; $Body .= $chicken_finger_platter; $Body .= "\nChicken Nugget Platter: "; $Body .= $chicken_nugget_platter; $Body .= "\nChicken Wing Platter: "; $Body .= $chicken_wing_platter; $Body .= "\n\nSALADS\n"; $Body .= "\nCaesar Salad: "; $Body .= $caesar_salad; $Body .= "\nHouse Salad: "; $Body .= $house_salad; $Body .= "\nCobb Salad: "; $Body .= $cobb_salad; $Body .= "\nSea Breeze Salad: "; $Body .= $sea_breeze_salad; $Body .= "\n\nAPPETIZERS\n"; $Body .= "\nFresh Fruit Platter: "; $Body .= $fresh_fruit_platter; $Body .= "\nChilled Vegetable Platter: "; $Body .= $chilled_vegetable_platter; $Body .= "\nCocktail Shrimp: "; $Body .= $cocktail_shrimp; $Body .= "\nTailgate Chips Platter: "; $Body .= $tailgate_chips_platter; $Body .= "\nChips and Salsa: "; $Body .= $chips_and_salsa; $Body .= "\nSpinach Artichoke Dip Platter: "; $Body .= $spinach_artichoke_dip_platter; $Body .= "\nQuesadilla Platter: "; $Body .= $quesadilla_platter; $Body .= "\n\nENTREES\n"; $Body .= "\nBBQ Ribs Platter: "; $Body .= $bbq_ribs_platter; $Body .= "\nHawaiian Chicken: "; $Body .= $hawaiian_chicken; $Body .= "\nMahi Over Rice: "; $Body .= $mahi_over_rice; $Body .= "\n\nSANDWICHES\n"; $Body .= "\nGourmet Slider Platter: "; $Body .= $gourmet_slider_platter; $Body .= "\nMini Cheeseburger Platter: "; $Body .= $mini_cheeseburger_platter; $Body .= "\nClub Sandwich Platter: "; $Body .= $club_sandwich_platter; $Body .= "\nTurkey Wrap Platter: "; $Body .= $turkey_wrap_platter; $Body .= "\nPhilly Cheese Platter: "; $Body .= $philly_cheese_platter; $Body .= "\n\nDESSERT\n"; $Body .= "\nChocolate Brownie Platter: "; $Body .= $chocolate_brownie_platter; $Body .= "\nApple Crisp: "; $Body .= $apple_crisp; $Body .= "\nMini Gourmet Cheesecakes: "; $Body .= $mini_gourmet_cheesecakes; $Body .= "\n\n$10 MEAL DEAL\n"; $Body .= "\nWings: "; $Body .= $meal_deal_wings; $Body .= "\nGrilled Chicken Breast: "; $Body .= $meal_deal_grilled_chicken; $Body .= "\nBurger: "; $Body .= $meal_deal_burger; $Body .= "\nLemonade: "; $Body .= $meal_deal_lemonade; $Body .= "\nIced Tea: "; $Body .= $meal_deal_iced_tea; $Body .= "\nWing Sauces: "; $Body .= "\n\nBOX LUNCHES\n"; $Body .= "\nSandwiches"; $Body .= "\nTurkey Ruben: "; $Body .= $box_turkey_ruben; $Body .= "\nBLT on Ciabatta Bread: "; $Body .= $box_blt_on_ciabatta; $Body .= "\nClub: "; $Body .= $box_club; $Body .= "\nHam and Cheese: "; $Body .= $box_ham_and_cheese; $Body .= "\n\nWraps"; $Body .= "\nChipolte Shrimp BLT: "; $Body .= $box_chipolte_shrimp_blt; $Body .= "\nTurkey Bacon Ranch: "; $Body .= $box_turkey_bacon_ranch; $Body .= "\nBuffalo Chicken: "; $Body .= $box_buffalo_chicken; $Body .= "\nVeggie: "; $Body .= $box_veggie; $Body .= "\n\nSalad"; $Body .= "\nCaesar Salad: "; $Body .= $box_caesar_salad; $Body .= "\nHouse Salad: "; $Body .= $box_house_salad; $Body .= "\nCobb Salad: "; $Body .= $box_cobb_salad; $Body .= "\nSea Breeze Salad: "; $Body .= $box_sea_breeze_salad; $Body .= "\n\nFULL SERVICE CATERING\n"; $Body .= "\nTheme Package: "; $Body .= $theme_package; $Body .= "\nInformation: "; $Body .= $theme_package_information; $Body .= "\nReception: "; $Body .= $reception; $Body .= "\nInformation: "; $Body .= $reception_information; $Body .= "\nSpecialty Stations: "; $Body .= $specialty_stations; $Body .= "\nBar/Beverage Service: "; $Body .= $bar_beverage_service; $Body .= "\nInformation: "; $Body .= $bar_beverage_service_information; $Body .= "\nBreakfast: "; $Body .= $breakfast; $Body .= "\nInformation: "; $Body .= $breakfast_information; $Body .= "\nNotes: "; $Body .= $notes; $Body .= "\n\nPAYMENT TYPE\n"; $Body .= "$payment1, $payment2, $payment3, $payment4, $payment5, $payment6"; $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>") && mail($EmailFrom, $confirmation_subject, $confirmation_body, "From: <$EmailTo>"); Link to comment Share on other sites More sharing options...
fugix Posted May 20, 2011 Share Posted May 20, 2011 you can use the empty() function to check if a var is empty... Link to comment Share on other sites More sharing options...
cdm30 Posted May 20, 2011 Author Share Posted May 20, 2011 you can use the empty() function to check if a var is empty... Could you show me an example? What I know of the empty function is like this: if(empty($username)) { echo "This variable is empty"; } else { echo "This variable is not empty"; } I have no idea how to use that to include in the email body or not.. I'm sorry. I want to learn but not sure where to start.. Link to comment Share on other sites More sharing options...
fugix Posted May 20, 2011 Share Posted May 20, 2011 in order to send mail using the mail function you need to have 3 parameters...to, subject , and a message Link to comment Share on other sites More sharing options...
cdm30 Posted May 20, 2011 Author Share Posted May 20, 2011 The message sends fine. Its just a long form and the client wants to exclude fields that are empty from being sent to his email. I guess I'm not understanding your advice, sorry :/ Link to comment Share on other sites More sharing options...
fugix Posted May 20, 2011 Share Posted May 20, 2011 think i might understand you...so you might want something like this if(!empty($chicken_wing_platter)) { $Body .= $chicken_wing_platter; } so if the field is empty it will not send that field...something like that? Link to comment Share on other sites More sharing options...
Psycho Posted May 20, 2011 Share Posted May 20, 2011 Did you notice you are doing the same thing (trim and stripslashes) for many, many inputs? Even though it is just two functions you should always make a function if you are doing something multiple times. If you were to move to a different server (or the current server's configuration was changed) where stripslashes was not needed you would have a LOT of editing to do. You can also make the function return the whole text needed for the email to server the purpose of your request here. I would also advise categorizing the input fields based upon the sections they will exist in the email (i.e. party platters, salads, appetizers, etc.). It will give more structure to the data and make the whole process easier to maintain. But, the code I provide below doesn't take that into account. Here is some code to get you started. This is how I would rewrite the code to handle the CONTACT and EVENT text. You should be able to continue on with the rest of the fields. The function formatPOST() does two things. 1) It modifies the input as necessary for use in the email AND if adds the label needed for the email text. The label is optional so you can use it to escape text without appending the label. function formatPOST($postValue, $label=false) { $postValue = trim(stripslashes($postValue)); //If nothing was posted return false if(empty($postValue)) { return false; } //Post value submitted, format value with label (if exists) if(!$label) { return $postValue; } else { return "{$label}: {$postValue}\n" } } function formattedAddress($street, $city, $state, $zip) { $street = formatPOST($street); $city = formatPOST($city); $state = formatPOST($state); $zip = formatPOST($zip); $parts = array(); if($street) { $parts[] = $street; } if($city) { $parts[] = $city; } if($state) { $parts[] = $state; } if($zip) { $parts[] = $zip; } return implode(', ', $parts); } //Format complete billing address $billingAddress = formattedAddress($_POST['billing_address'], $_POST['billing_city'], $_POST['billing_state'], $_POST['billing_zip']); //Format complete event address $eventAddress = formattedAddress($_POST['event_address'], $_POST['event_city'], $_POST['event_state'], $_POST['event_zip']); //Create CONTACT text $Body = "CONTACT INFORMATION\n"; $Body .= formatPOST($_POST['full_name'], "Full Name"); $Body .= formatPOST($_POST['title'], "Title"); $Body .= formatPOST($_POST['company'], "Company"); $Body .= "Billing Address: {$billingAddress}\n"; $Body .= formatPOST($_POST['phone'], "Phone"); $Body .= formatPOST($_POST['alt_phone'], "Alternate PhoneAlternate Phone"); $Body .= formatPOST($_POST['how_did_you_hear'], "How did you hear about us?"); $Body .= formatPOST($_POST['full_name'], "Full Name"); $Body .= $terms_conditions_details; //Create EVENT text $Body .= "\n\nEVENT INFORMATION\n"; $Body .= formatPOST($_POST['event_date'], "Event Date"); $Body .= formatPOST($_POST['guests'], "Number of Guests"); $Body .= formatPOST($_POST['event_start_time'], "Event Start Time"); $Body .= formatPOST($_POST['event_end_time'], "Event End Time"); $Body .= "Billing Address: {$eventAddress}\n"; $Body .= formatPOST($_POST['event_type'], "nType of Event"); $Body .= formatPOST($_POST['event_type_other'], "Type of Event: Other"); $Body .= formatPOST($_POST['event_theme'], "Event Theme"); $Body .= formatPOST($_POST['special_requests'], "Special Requests"); $Body .= formatPOST($_POST['budget'], "Budget"); $Body .= formatPOST($_POST['service_type'], "Type of Service"); Link to comment Share on other sites More sharing options...
cdm30 Posted May 20, 2011 Author Share Posted May 20, 2011 Thank you both so much!! MJDAMATO you're awesome.. I have enough to learn from, thank you!! Link to comment Share on other sites More sharing options...
Psycho Posted May 20, 2011 Share Posted May 20, 2011 MJDAMATO you're awesome.. No need to point out the obvious. Although, I will say it is refreshing to see someone who understands the difference between "your" and "you're". Link to comment Share on other sites More sharing options...
cdm30 Posted May 20, 2011 Author Share Posted May 20, 2011 HAHAHA for some reason saying "a lot" and "you're" properly make me feel whole Link to comment Share on other sites More sharing options...
fugix Posted May 20, 2011 Share Posted May 20, 2011 MJDAMATO you're awesome.. No need to point out the obvious. Although, I will say it is refreshing to see someone who understands the difference between "your" and "you're". LOL Link to comment Share on other sites More sharing options...
tommhans Posted January 11, 2013 Share Posted January 11, 2013 Hi im new here, just came over this post and i have the same problem that i want to exclude empty forms, The way ive set mine up is that i use dropdown list instead of a normal input form and i've set up the forms so that they have an empty blank option on the top aswell, but yeah i have no idea where to start with this exluding form, the one example you helped him with didn't work for me. Ill post a short version of the php part of the script(as it is quite long, over 2000 lines ) you can have a look at the site i'm working on here <?php $page = $_GET['page']; function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } function sjekk_kontakt_data($a) { /* * Sjekker at alle felt som skal være fylt ut, er det. */ if ((strlen($a['check']) <= 0) || (strlen($a['email']) <= 0) || (strlen($a['body']) <= 0)) { sett_error_melding(hent_linje(7, $SYSTEM_LANG_FIL)); return false; } /* * Sjekker at E-post adressen er riktig. */ if (!gyldig_epost($a['email'])) { sett_error_melding(hent_linje(18, $SYSTEM_LANG_FIL)); return false; } return true; } function gyldig_epost($adresse) { if (ereg("^[a-zA-Z0-9.\-\_\-]+@[a-zA-Z0-9\-]+\.[a-zA-z0-9\-\.]+$", $adresse)) { return true; } else { return false; } } if (isset($_POST['email'])) {//if "email" is filled out, proceed //check if the email address is invalid $mailcheck = spamcheck($_POST['email']); if ($mailcheck==FALSE) { echo "Invalid input"; } //spamcheck else {//send email //Spamcheck //this is the antall varer part //pilotjakke grå// $vare1 = $_POST['prod1']; $vare2 = $_POST['prod2']; $vare3 = $_POST['prod3']; $vare4 = $_POST['prod4']; $vare5 = $_POST['prod5']; $pilotjakkegrå= "\n Pilotjakke pelsforet Grå Small: $vare1\r\n Pilotjakke pelsforet Grå Medium: $vare2\r\n Pilotjakke pelsforet Grå Large: $vare3\r\n Pilotjakke pelsforet Grå X-Large: $vare4\r\n Pilotjakke pelsforet Grå XX-Large: $vare5\r\n "; //Allværsjakke orrange/gul $vare01 = $_POST['test1']; $vare07 = $_POST['test2']; $vare08 = $_POST['test3']; $vare09 = $_POST['test4']; $vare00 = $_POST['test5']; $allværorgul= "\n Allværsjakke kombi oransj/gul Small: $vare01\r\n Allværsjakke kombi oransj/gul Medium: $vare02\r\n Allværsjakke kombi oransj/gul Large: $vare03\r\n Allværsjakke kombi oransj/gul X-Large: $vare04\r\n Allværsjakke kombi oransj/gul XX-Large: $vare05\r\n "; //pilotjakke blå $vare6 = $_POST['sumpbb1']; $vare7 = $_POST['sumpbb2']; $pilotjakkeblå= "\n Pilotjakke pelsforet Blå Small: $vare6\r\n Pilotjakke pelsforet Blå Medium: $vare7\r\n "; //vinterkjeledresser $vare8 = $_POST['vint1']; $vare9 = $_POST['vint12']; $vare10 = $_POST['vint2']; $vare11 = $_POST['vint3']; $vare12 = $_POST['vint4']; $vare13 = $_POST['vint5']; $vare14 = $_POST['vint6']; $vare15 = $_POST['vint7']; $vare16 = $_POST['vint8']; $vinterkjeledress= "\n Vinterkjeledress Blåklæder Str:46 : $vare8\r\n Vinterkjeledress Blåklæder Str:48: $vare9\r\n Vinterkjeledress Blåklæder Str:50: $vare10\r\n Vinterkjeledress Blåklæder Str:52: $vare11\r\n Vinterkjeledress Blåklæder Str:54: $vare12\r\n Vinterkjeledress Blåklæder Str:56: $vare13\r\n Vinterkjeledress Blåklæder Str:58: $vare14\r\n Vinterkjeledress Blåklæder Str:60: $vare15\r\n Vinterkjeledress Blåklæder Str:62: $vare16\r\n "; //pilotjakke univern rød $vare21 = $_POST['univrød1']; $vare22 = $_POST['univrød2']; $vare23 = $_POST['univrød3']; $jakkeunivrød= "\n Pilotjakke Univern Rød Small: $vare21\r\n Pilotjakke Univern Rød Medium: $vare22\r\n Pilotjakke Univern Rød X-Large: $vare23\r\n "; //protec selebukse svart $vare24 = $_POST['selebukse1']; $vare25 = $_POST['selebukse2']; $vare26 = $_POST['selebukse3']; $vare27 = $_POST['selebukse4']; $selebukse= "\n Protec Combi Vinterbukse m/seler Medium: $vare24\r\n Protec Combi Vinterbukse m/seler Large: $vare25\r\n Protec Combi Vinterbukse m/seler X-Large: $vare26\r\n Protec Combi Vinterbukse m/seler XX-Large: $vare27\r\n "; //vinterjakke $vare28 = $_POST['jakkevint1']; $vare29 = $_POST['jakkevint2']; $vare30 = $_POST['jakkevint3']; $vare31 = $_POST['jakkevint4']; $vare32 = $_POST['jakkevint5']; $vare33 = $_POST['jakkevint6']; $provinterjakke= "\n Protec Vinterjakke Svart/Orange Small: $vare28\r\n Protec Vinterjakke Svart/Orange Medium: $vare29\r\n Protec Vinterjakke Svart/Orange Large: $vare30\r\n Protec Vinterjakke Svart/Orange X-Large: $vare31\r\n Protec Vinterjakke Svart/Orange XX-Large: $vare32\r\n Protec Vinterjakke Svart/Grå XX-Large: $vare33\r\n "; "; //varer om til php $varer=" Pilotjakke pelsforet Grå: \r\n $pilotjakkegrå \r\n\r\n Allværsjakke kombi oransj/gul: \r\n $allværorgul \r\n\r\n Pilotjakke pelsforet Blå: \r\n $pilotjakkeblå \r\n\r\n Vinterkjeledress Blåklæder: \r\n $vinterkjeledress \r\n\r\n Pilotjakke Univern Rød: \r\n $jakkeunivrød \r\n\r\n Protec Combi Vinterbukse m/seler: \r\n $selebukse \r\n\r\n Protec Combi Vinterbukse m/seler: \r\n $selebukse \r\n\r\n Protec Vinterjakke Svart/Orange: \r\n $provinterjakke \r\n\r\n Lofoten Vinterdress Rød: \r\n $lofoten \r\n\r\n Pilotjakke pelsforet Grå/Rød: \r\n $pilotgrårød \r\n\r\n Allværsjakke kombi gul/blå: \r\n $allgulblå \r\n\r\n Allværsbukse kombi oransj/gul: \r\n $allbukseorgul \r\n\r\n Protec Allværsbukse svart: \r\n $probukse \r\n\r\n Vinterjakke Rød Univern: \r\n $vintrød \r\n\r\n Fleecejakke EN471 Orange: \r\n $fleece \r\n\r\n Thermo Vest: \r\n $thermo \r\n\r\n "; //varer $order = $_POST['order_total']; $to = $_POST['email']; $to = "tommy@premiere-produkter.no"; $subject = "Lagersalg Bestilling"; $subject ='=?UTF-8?B?'.base64_encode($subject).'?='; $antall = $_POST['antall']; $name_field = $_POST['name']; $email_field = $_POST['email']; $email2 = $_POST['email2'];; $message = $_POST['message']; $name_field = $_POST['name'] ; $tlf = $_POST['tlf'] ; $firma = $_POST['firma'] ; $header = "MIME-Version: 1.0"; $header .= "Content-type: text/plain; charset=utf-8"; $header .= "From: \"$name_field\" <$email_field>"; $header .= "Reply-To: \"$name_field\" <$email_field>"; $header .= 'BCC: tommy@premiere-produkter.no'; $header .= 'CC: tommy@premiere-produkter.no'; $header .= "Return-Path: \"$name_field\" <$email_field>"; // these two to set reply address $header .= "Message-ID:<".$now." TheSystem@".$_SERVER['SERVER_NAME'].">"; $header .= "X-Mailer: PHP v".phpversion(); // These two to help avoid spam-filters # Boundry for marking the split & Multitype Headers $mime_boundary=md5(time()); $body = " =========================================== $varer =========================================== \r\n\r\n Navn: $name_field\r\n =========================================== E-Mail: $email_field\r\n =========================================== Firma: $firma\r\n =========================================== Telefon: $tlf\r\n =========================================== Message: $message\r\n\r\n =========================================== "; if (mail($to,$subject, $body, $header)) { $myFile = "testFile.txt"; $fh = fopen($myFile, 'a+') or die("can't open file"); $stringData = $body; fwrite($fh, $stringData); fclose($fh); } else { } } } else //send mail og slikt ?> Yeah im norwegian so alot of it is in norwegian, varer = products, and i have 70 of em , and as you see ive grouped them up so it will be easier to edit later on. The html post is like this: <form id="form2" method="POST" action="index.php" name="form"> <div id="contact_box"> <h2> Total pris for alle varene du har valgt ut: <input name="totalsum" onchange="updatesum()" readonly style="border:0px;"></h2> <h2><INPUT TYPE=RESET VALUE="Resett formen"></h2> <h4><b>Registrering, MÅ UTFØRES før du bestiller</b></h4> <p> <label for="name">Navn: </label> <input type="text" name="name" size="19" placeholder="Ditt fulle navn?"> </p> <p> <label for="firma">Firma: </label> <input type="text" name="firma" size="19" placeholder="Hvilket firma er du fra?"> </p> <p> <label for="email">E-Post: </label> <input type="text" name="email" size="19" placeholder="Hva er e-posten adressen di?"> </p> <p> <label for="tlf">Telefon: </label> <input type="text" name="tlf" size="19" placeholder="Hvor mange vil du ha med deg?"> </p> <label for="message">Melding: </label> <input type="text" name="message" size="39" id="message" placeholder="Noe mer du vil tilføye?"> <p></p> <input type="hidden" name="email2" value="tommy@premiere-produkter.no"> <input type="submit" class="submit2" size="19" value="Bestill orderen" name="submit"> Du vil motta en bekreftelse på din varebestilling og deretter motta en faktura når vi har fått gått igjennom orderen. </div> <!--email form--> <div id="content"> <p><div id="imgcontent"> <a href="#" id="example3-show" class="showLink" onclick= "showHide('example3');return false;"><img src="style/img/70251.png" /></a><br></p> <div id="example3" class="more"> <p><b>Pilotjakke pelsforet</b></p> <p>70% polyester / 30% bomull</p> <p>To brystlommer med glidelås, telefonlomme, innerlomme, to frontlommer med knapp og armlomme med glidelås.</p> <p>Leveres i følgende farger: Grå</p> <p>Leveres i str: <b>S-XXL</b></p> <p>Pris per stk <b>kr 349</b></p> <br /> <label for="prod1">Pilotjakke pelsforet, <b>Small</b>: </label> <select name="prod1" value="antall" placeholder="Antallet du vil bestille?" onchange="updatesum()"> <option value""></option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> </SELECT> <!--Small--> <label for="prod2">Pilotjakke pelsforet, <b>Medium</b>: </label> <select name="prod2" value="antall" placeholder="Antallet du vil bestille?" onchange="updatesum()"> <option value""></option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> </SELECT> <!--Medium--> <label for="prod3">Pilotjakke pelsforet,<b>Large</b>: </label> <select name="prod3" value="antall" placeholder="Antallet du vil bestille?" onchange="updatesum()"> <option value""></option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> </SELECT> <!--Large--> <label for="prod4">Pilotjakke pelsforet,<b>X-Large</b>: </label> <select name="prod4" value="antall" placeholder="Antallet du vil bestille?" onchange="updatesum()"> <option value""></option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> </SELECT> <!--XXL pilojakkepelsfor--> <label for="prod5">Pilotjakke pelsforet,<b>XXL</b>: </label> <select name="prod5" value="antall" placeholder="Antallet du vil bestille?" onchange="updatesum()"> <option value""></option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> </SELECT><!--XXL pilojakkepelsfor--> <br /> </p> Total sum på produktet: kr <input name="smu" onchange="updatesum()" readonly style="border:0px;"> <p><a href="#" id="example3-hide" class="hideLink" onclick="showHide('example3');return false;">Gjem denne infoen</a></p> </div> <p><h2>Pilotjakke pelsforet</h2></p> </div> <!--This is how every form looks like, same setup just different names and quantity--> </form> Any help would be appreciated, sorry for the long post! Also i have another question, i want the mail to send mail to both me and to the user writing his mail in the input form, how would i go on about doing that(just did not get this to work) cheers, Tommy Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 11, 2013 Share Posted January 11, 2013 Start your own thread for your problem. Topic locked. Link to comment Share on other sites More sharing options...
Recommended Posts