autoworld Posted April 12, 2011 Share Posted April 12, 2011 Hello all. I'm a newbie to this site and PHP and trying to build a basic contact/info form for an insurance company. I've been testing what I've done in FF, IE, and Google Chrome, and it seems to be generating consistent results ... but I thought I'd run it past the EXPERTS here, so you can tell me all that I've done wrong. : ) Attached is the PHP page that is triggered by a basic HTML page with check boxes, etc. And below is what a resulting email looks like, which is fine by me (of course this is empty). Thanks for any advice! -RP ------------------------------------------------- Name: Tel: Company: State: Website: Employees: ===== Type of Business ===== Manufacturer: Retailer: Jobber/Restyler: Distributor: Motorsports: Professional Services: ===== Insurance Needs ===== General Liability: Garage/Keepers: Property Building: Property Equipment: Loss of Income: Worker's Comp.: Internet Liability: Life & Disability: Product Liability: Legal Liability: Property Contents: Cargo/Mobile Property: Employee Dishonesty: 401K & Retirement: Health: Other: Personal Comments: ========================= [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/ Share on other sites More sharing options...
QuickOldCar Posted April 12, 2011 Share Posted April 12, 2011 To save some from downloading. wrap code in tags. [code=php:0] [/code] <?php // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "my email address here"; $Subject = "I need a quote"; $Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Company = Trim(stripslashes($_POST['Company'])); $State = Trim(stripslashes($_POST['State'])); $Website = Trim(stripslashes($_POST['Website'])); $Manufacturer = Trim(stripslashes($_POST['Manufacturer'])); $Retailer = Trim(stripslashes($_POST['Retailer'])); $JobberRestyler = Trim(stripslashes($_POST['JobberRestyler'])); $Distributor = Trim(stripslashes($_POST['Distributor'])); $Motorsports = Trim(stripslashes($_POST['Motorsports'])); $ProfessionalServices = Trim(stripslashes($_POST['ProfessionalServices'])); $Employees = Trim(stripslashes($_POST['Employees'])); $GeneralLiability = Trim(stripslashes($_POST['GeneralLiability'])); $GarageKeepers = Trim(stripslashes($_POST['GarageKeepers'])); $PropertyBuilding = Trim(stripslashes($_POST['PropertyBuilding'])); $PropertyEquipment = Trim(stripslashes($_POST['PropertyEquipment'])); $LossofIncome = Trim(stripslashes($_POST['LossofIncome'])); $WorkersComp = Trim(stripslashes($_POST['WorkersComp'])); $InternetLiability = Trim(stripslashes($_POST['InternetLiability'])); $LifeDisability = Trim(stripslashes($_POST['LifeDisability'])); $ProductLiability = Trim(stripslashes($_POST['ProductLiability'])); $LegalLiability = Trim(stripslashes($_POST['LegalLiability'])); $PropertyContents = Trim(stripslashes($_POST['PropertyContents'])); $CargoMobileProperty = Trim(stripslashes($_POST['CargoMobileProperty'])); $EmployeeDishonesty = Trim(stripslashes($_POST['EmployeeDishonesty'])); $Retirement = Trim(stripslashes($_POST['Retirement'])); $Health = Trim(stripslashes($_POST['Health'])); $Other = Trim(stripslashes($_POST['Other'])); $Comments = Trim(stripslashes($_POST['Comments'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Tel)=="") $validationOK=false; if (Trim($State)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Company: "; $Body .= $Company; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Website: "; $Body .= $Website; $Body .= "\n"; $Body .= "Employees: "; $Body .= $Employees; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Type of Business ====="; $Body .= "\n"; $Body .= "Manufacturer: "; $Body .= $Manufacturer; $Body .= "\n"; $Body .= "Retailer: "; $Body .= $Retailer; $Body .= "\n"; $Body .= "Jobber/Restyler: "; $Body .= $JobberRestyler; $Body .= "\n"; $Body .= "Distributor: "; $Body .= $Distributor; $Body .= "\n"; $Body .= "Motorsports: "; $Body .= $Motorsports; $Body .= "\n"; $Body .= "Professional Services: "; $Body .= $ProfessionalServices; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Insurance Needs ====="; $Body .= "\n"; $Body .= "General Liability: "; $Body .= $GeneralLiability; $Body .= "\n"; $Body .= "Garage/Keepers: "; $Body .= $GarageKeepers; $Body .= "\n"; $Body .= "Property Building: "; $Body .= $PropertyBuilding; $Body .= "\n"; $Body .= "Property Equipment: "; $Body .= $PropertyEquipment; $Body .= "\n"; $Body .= "Loss of Income: "; $Body .= $LossofIncome; $Body .= "\n"; $Body .= "Worker's Comp.: "; $Body .= $WorkersComp; $Body .= "\n"; $Body .= "Internet Liability: "; $Body .= $InternetLiability; $Body .= "\n"; $Body .= "Life & Disability: "; $Body .= $LifeDisability; $Body .= "\n"; $Body .= "Product Liability: "; $Body .= $ProductLiability; $Body .= "\n"; $Body .= "Legal Liability: "; $Body .= $LegalLiability; $Body .= "\n"; $Body .= "Property Contents: "; $Body .= $PropertyContents; $Body .= "\n"; $Body .= "Cargo/Mobile Property: "; $Body .= $CargoMobileProperty; $Body .= "\n"; $Body .= "Employee Dishonesty: "; $Body .= $EmployeeDishonesty; $Body .= "\n"; $Body .= "401K & Retirement: "; $Body .= $Retirement; $Body .= "\n"; $Body .= "Health: "; $Body .= $Health; $Body .= "\n"; $Body .= "Other: "; $Body .= $Other; $Body .= "\n"; $Body .= "\n"; $Body .= "Personal Comments: "; $Body .= $Comments; $Body .= "\n"; $Body .= "\n"; $Body .= "========================="; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200805 Share on other sites More sharing options...
dcro2 Posted April 12, 2011 Share Posted April 12, 2011 Protip: use [nobbc][/nobbc] to tell people to wrap their code in or tags Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200807 Share on other sites More sharing options...
autoworld Posted April 12, 2011 Author Share Posted April 12, 2011 Thanks so much for your quick replies. Here's the problem though: I'm expert at many things, but not this stuff ... I'm just getting started, i.e., you're giving me waaay too much credit. I learn by example so ... is there any way you can post an example of what you meant? If it's too much trouble, I understand how it goes. -RP Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200818 Share on other sites More sharing options...
QuickOldCar Posted April 12, 2011 Share Posted April 12, 2011 We didn't comment on your code, merely expressing to place them onto the site in code tags versus uploading them. Will get more responses if people can see it easily. Looking at it....it's quite a large piece of code with many POST fields. Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200826 Share on other sites More sharing options...
autoworld Posted April 12, 2011 Author Share Posted April 12, 2011 Ah, I see ... okay ... well if anyone can suggest how I streamline it, I owe them a beer or three.And if this is too rudimentary for you guys, that's understandable. I've just done the best I can with what I know ... so far that is. You mean post it like this I suppose: --------------- <?php // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "my email address here"; $Subject = "I need a quote"; $Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Company = Trim(stripslashes($_POST['Company'])); $State = Trim(stripslashes($_POST['State'])); $Website = Trim(stripslashes($_POST['Website'])); $Manufacturer = Trim(stripslashes($_POST['Manufacturer'])); $Retailer = Trim(stripslashes($_POST['Retailer'])); $JobberRestyler = Trim(stripslashes($_POST['JobberRestyler'])); $Distributor = Trim(stripslashes($_POST['Distributor'])); $Motorsports = Trim(stripslashes($_POST['Motorsports'])); $ProfessionalServices = Trim(stripslashes($_POST['ProfessionalServices'])); $Employees = Trim(stripslashes($_POST['Employees'])); $GeneralLiability = Trim(stripslashes($_POST['GeneralLiability'])); $GarageKeepers = Trim(stripslashes($_POST['GarageKeepers'])); $PropertyBuilding = Trim(stripslashes($_POST['PropertyBuilding'])); $PropertyEquipment = Trim(stripslashes($_POST['PropertyEquipment'])); $LossofIncome = Trim(stripslashes($_POST['LossofIncome'])); $WorkersComp = Trim(stripslashes($_POST['WorkersComp'])); $InternetLiability = Trim(stripslashes($_POST['InternetLiability'])); $LifeDisability = Trim(stripslashes($_POST['LifeDisability'])); $ProductLiability = Trim(stripslashes($_POST['ProductLiability'])); $LegalLiability = Trim(stripslashes($_POST['LegalLiability'])); $PropertyContents = Trim(stripslashes($_POST['PropertyContents'])); $CargoMobileProperty = Trim(stripslashes($_POST['CargoMobileProperty'])); $EmployeeDishonesty = Trim(stripslashes($_POST['EmployeeDishonesty'])); $Retirement = Trim(stripslashes($_POST['Retirement'])); $Health = Trim(stripslashes($_POST['Health'])); $Other = Trim(stripslashes($_POST['Other'])); $Comments = Trim(stripslashes($_POST['Comments'])); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Tel)=="") $validationOK=false; if (Trim($State)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Company: "; $Body .= $Company; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Website: "; $Body .= $Website; $Body .= "\n"; $Body .= "Employees: "; $Body .= $Employees; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Type of Business ====="; $Body .= "\n"; $Body .= "Manufacturer: "; $Body .= $Manufacturer; $Body .= "\n"; $Body .= "Retailer: "; $Body .= $Retailer; $Body .= "\n"; $Body .= "Jobber/Restyler: "; $Body .= $JobberRestyler; $Body .= "\n"; $Body .= "Distributor: "; $Body .= $Distributor; $Body .= "\n"; $Body .= "Motorsports: "; $Body .= $Motorsports; $Body .= "\n"; $Body .= "Professional Services: "; $Body .= $ProfessionalServices; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Insurance Needs ====="; $Body .= "\n"; $Body .= "General Liability: "; $Body .= $GeneralLiability; $Body .= "\n"; $Body .= "Garage/Keepers: "; $Body .= $GarageKeepers; $Body .= "\n"; $Body .= "Property Building: "; $Body .= $PropertyBuilding; $Body .= "\n"; $Body .= "Property Equipment: "; $Body .= $PropertyEquipment; $Body .= "\n"; $Body .= "Loss of Income: "; $Body .= $LossofIncome; $Body .= "\n"; $Body .= "Worker's Comp.: "; $Body .= $WorkersComp; $Body .= "\n"; $Body .= "Internet Liability: "; $Body .= $InternetLiability; $Body .= "\n"; $Body .= "Life & Disability: "; $Body .= $LifeDisability; $Body .= "\n"; $Body .= "Product Liability: "; $Body .= $ProductLiability; $Body .= "\n"; $Body .= "Legal Liability: "; $Body .= $LegalLiability; $Body .= "\n"; $Body .= "Property Contents: "; $Body .= $PropertyContents; $Body .= "\n"; $Body .= "Cargo/Mobile Property: "; $Body .= $CargoMobileProperty; $Body .= "\n"; $Body .= "Employee Dishonesty: "; $Body .= $EmployeeDishonesty; $Body .= "\n"; $Body .= "401K & Retirement: "; $Body .= $Retirement; $Body .= "\n"; $Body .= "Health: "; $Body .= $Health; $Body .= "\n"; $Body .= "Other: "; $Body .= $Other; $Body .= "\n"; $Body .= "\n"; $Body .= "Personal Comments: "; $Body .= $Comments; $Body .= "\n"; $Body .= "\n"; $Body .= "========================="; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200830 Share on other sites More sharing options...
spiderwell Posted April 12, 2011 Share Posted April 12, 2011 testing in different browsers shouldn't be relevant when using PHP, also I would say that you haven't really done anything wrong in your code, it all works and validates how you want it to, thats a lot bette rthan some people can manage. I don't think you need to worry about using stripslashes(), its not really needed when validating input from a form directly into an email format. it was really the partner to addslashes() which is used to escape certain characters in a string especially in conjunction with inputs into databases to stop SQL querys breaking. looking at your form I would say it works fine, but the validation is moderate to low, by that I mean you only check a few variables for having an entry and thats all. I guess it depends on the needs of your client how far you can go with this, but it is possible to validate to almost any specification, obvious ones being telephone numbers, emails, addresses all having only the right data, e.g. numbers only, text only, email is an email address . php can do redirects rather than sending a refresh header using header('Location: http://www.example.com/'), not sure if you knew that one or not. otherwise I would say well done on creating a sucessful script. [ code ] put scripts in here [ / code ] Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200834 Share on other sites More sharing options...
autoworld Posted April 12, 2011 Author Share Posted April 12, 2011 Spiderwell, thanks so much for the encouragement and the kudos. First, are you saying I can pull all the "Trim(stripslashes)" comments out globally? For example: OLD: $Tel = Trim(stripslashes($_POST['Tel'])); NEW: $Tel = ($_POST['Tel']); The minimal validations are because this is a marketing/sales page, and I don't want to make prospective clients to work too hard, lest they turn away too soon. However, if there is a way to make sure their email addy is valid, that'd be super! I tried to validate the phone number, but I found if they added parenthesis or periods (not digits), which caused me issues/concern. Again, I did not want to force the prospective client to "conform" lest they click away. I defaulted to just "fill something in, and we'll try to figure it out." Ha ha. As for redirects, as you mention, I assume you mean I could have placed ANY relative or absolute link in there, no? If so, that I get. Thank you again for your time in helping me. Same goes for all you guys.... -RP Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200851 Share on other sites More sharing options...
spiderwell Posted April 12, 2011 Share Posted April 12, 2011 keep the trim() that cuts off white space on the inputted data at the ends of i.e. " my name " become "my name" there is a validate email function, but it isnt built into php, you need to make a regular expression check against the input, I would say learning how to write one might be a bit hard, they aren't the easiest things in php (for me at least) here's one i prepared eariler as they say: function validateEmail($themail){ $result = preg_match ("/^[^@ ]+@[^@ ]+\.[^@ \.]+$/", $themail ); if ($result){ return true; }else{ return false; } } stick that in the top of your php and then use it later on in your validation, its a function that returns true if email is valid, false if not if (Trim($State)=="") $validationOK=false; if (!validateEmail($EmailFrom)) $validationOK=false; Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200856 Share on other sites More sharing options...
Pikachu2000 Posted April 12, 2011 Share Posted April 12, 2011 Trim()ming the form data is fine. Saves you some aggravation from some bonehead that doesn't realize they've laid on the space bar for 4 minutes after filling out a form field. Using stripslashes() shouldn't be necessary as long as magic_quotes_gpc() is off in your php.ini file. If it isn't, and you're able to do so, turn it off. If it's on and you aren't able to turn it off, or you just want your code to be as portable as possible, use a function to check for it, and apply stripslashes() as necessary. You can then also replace all of the individual trim(stripslashes()) with one call to array_map(), as long as $_POST isn't multidimensional since array_map() isn't recursive. function TRIM_STRIP($string) { if( get_magic_quotes_gpc() === TRUE ) { $string = stripslashes($string); } $string = trim($string); $string = preg_replace('~[\s]{2,}~', ' ', $string); // Replace multiple spaces with one space, remove or comment out if not needed . . . return $string; } $trimmed = array_map('TRIM_STRIP', $_POST); Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200869 Share on other sites More sharing options...
autoworld Posted April 13, 2011 Author Share Posted April 13, 2011 Ooooh boy, I am starting to feel like an amateur right quick. You guys are talking about thing above my pay grade. : ) Instead of just talking about how to do it, would anyone care to show me what a properly cleaned up file should look like, so I can do a side-by-side comparison? I'd be willing to pay a few bucks for your trouble (honest). If not, I'll just experiment and tweak, test, tweak, test ... and hope I don't break it! Ha ha. Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1200920 Share on other sites More sharing options...
autoworld Posted April 13, 2011 Author Share Posted April 13, 2011 So, I employed the suggestions and placed this on the server ... so far it works nicely ... than's all! Only one thing I notice, if I add a plural an apostrophe-s to a word ("word's"), it comes in as "word\'s" ... is that by design? I tried adding the suggested code by Pikachu2000, but there was no change. Perhaps I did something wrong. Thanks again friends. ------------------------------ <?php function validateEmail($EmaiFrom){ $result = preg_match ("/^[^@ ]+@[^@ ]+\.[^@ \.]+$/", $EmaiFrom ); if ($result){ return true; }else{ return false; } } // get posted data into local variables $EmailFrom = ($_POST['EmailFrom']); $EmailTo = "my email @ email.com"; $Subject = "I need a quote"; $Name = ($_POST['Name']); $Tel = ($_POST['Tel']); $Company = ($_POST['Company']); $State = ($_POST['State']); $Website = ($_POST['Website']); $Manufacturer = ($_POST['Manufacturer']); $Retailer = ($_POST['Retailer']); $JobberRestyler = ($_POST['JobberRestyler']); $Distributor = ($_POST['Distributor']); $Motorsports = ($_POST['Motorsports']); $ProfessionalServices = ($_POST['ProfessionalServices']); $Employees = ($_POST['Employees']); $GeneralLiability = ($_POST['GeneralLiability']); $GarageKeepers = ($_POST['GarageKeepers']); $PropertyBuilding = ($_POST['PropertyBuilding']); $PropertyEquipment = ($_POST['PropertyEquipment']); $LossofIncome = ($_POST['LossofIncome']); $WorkersComp = ($_POST['WorkersComp']); $InternetLiability = ($_POST['InternetLiability']); $LifeDisability = ($_POST['LifeDisability']); $ProductLiability = ($_POST['ProductLiability']); $LegalLiability = ($_POST['LegalLiability']); $PropertyContents = ($_POST['PropertyContents']); $CargoMobileProperty = ($_POST['CargoMobileProperty']); $EmployeeDishonesty = ($_POST['EmployeeDishonesty']); $Retirement = ($_POST['Retirement']); $Health = ($_POST['Health']); $Other = ($_POST['Other']); $Comments = ($_POST['Comments']); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Tel)=="") $validationOK=false; if (Trim($State)=="") $validationOK=false; if (!validateEmail($EmailFrom)) $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Company: "; $Body .= $Company; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Website: "; $Body .= $Website; $Body .= "\n"; $Body .= "Employees: "; $Body .= $Employees; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Type of Business ====="; $Body .= "\n"; $Body .= "Manufacturer: "; $Body .= $Manufacturer; $Body .= "\n"; $Body .= "Retailer: "; $Body .= $Retailer; $Body .= "\n"; $Body .= "Jobber/Restyler: "; $Body .= $JobberRestyler; $Body .= "\n"; $Body .= "Distributor: "; $Body .= $Distributor; $Body .= "\n"; $Body .= "Motorsports: "; $Body .= $Motorsports; $Body .= "\n"; $Body .= "Professional Services: "; $Body .= $ProfessionalServices; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Insurance Needs ====="; $Body .= "\n"; $Body .= "General Liability: "; $Body .= $GeneralLiability; $Body .= "\n"; $Body .= "Garage/Keepers: "; $Body .= $GarageKeepers; $Body .= "\n"; $Body .= "Property Building: "; $Body .= $PropertyBuilding; $Body .= "\n"; $Body .= "Property Equipment: "; $Body .= $PropertyEquipment; $Body .= "\n"; $Body .= "Loss of Income: "; $Body .= $LossofIncome; $Body .= "\n"; $Body .= "Worker's Comp.: "; $Body .= $WorkersComp; $Body .= "\n"; $Body .= "Internet Liability: "; $Body .= $InternetLiability; $Body .= "\n"; $Body .= "Life & Disability: "; $Body .= $LifeDisability; $Body .= "\n"; $Body .= "Product Liability: "; $Body .= $ProductLiability; $Body .= "\n"; $Body .= "Legal Liability: "; $Body .= $LegalLiability; $Body .= "\n"; $Body .= "Property Contents: "; $Body .= $PropertyContents; $Body .= "\n"; $Body .= "Cargo/Mobile Property: "; $Body .= $CargoMobileProperty; $Body .= "\n"; $Body .= "Employee Dishonesty: "; $Body .= $EmployeeDishonesty; $Body .= "\n"; $Body .= "401K & Retirement: "; $Body .= $Retirement; $Body .= "\n"; $Body .= "Health: "; $Body .= $Health; $Body .= "\n"; $Body .= "Other: "; $Body .= $Other; $Body .= "\n"; $Body .= "\n"; $Body .= "Personal Comments: "; $Body .= $Comments; $Body .= "\n"; $Body .= "\n"; $Body .= "========================="; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1201225 Share on other sites More sharing options...
Pikachu2000 Posted April 13, 2011 Share Posted April 13, 2011 If you use the function I posted, the values in the $_POST array are mapped to a new array, $trimmed, so you'd access the values as $trimmed['Name'], $trimmed['Tel'], etc. Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1201307 Share on other sites More sharing options...
autoworld Posted April 13, 2011 Author Share Posted April 13, 2011 Sorry for sounding like such a newbie ... do you mean like this? <?php function validateEmail($EmaiFrom){ $result = preg_match ("/^[^@ ]+@[^@ ]+\.[^@ \.]+$/", $EmaiFrom ); if ($result){ return true; }else{ return false; } } function TRIM_STRIP($string) { if( get_magic_quotes_gpc() === TRUE ) { $string = stripslashes($string); } $string = trim($string); $string = preg_replace('~[\s]{2,}~', ' ', $string); // Replace multiple spaces with one space, remove or comment out if not needed . . . return $string; } $trimmed = array_map('TRIM_STRIP', $_POST); // get posted data into local variables $EmailFrom = ($trimmed['EmailFrom']); $EmailTo = "robertoprosser@gmail.com"; $Subject = "I need a quote"; $Name = ($trimmed['Name']); $Tel = ($trimmed['Tel']); $Company = ($trimmed['Company']); $State = ($trimmed['State']); $Website = ($trimmed['Website']); $Manufacturer = ($trimmed['Manufacturer']); $Retailer = ($trimmed['Retailer']); $JobberRestyler = ($trimmed['JobberRestyler']); $Distributor = ($trimmed['Distributor']); $Motorsports = ($trimmed['Motorsports']); $ProfessionalServices = ($trimmed['ProfessionalServices']); $Employees = ($trimmed['Employees']); $GeneralLiability = ($trimmed['GeneralLiability']); $GarageKeepers = ($trimmed['GarageKeepers']); $PropertyBuilding = ($trimmed['PropertyBuilding']); $PropertyEquipment = ($trimmed['PropertyEquipment']); $LossofIncome = ($trimmed['LossofIncome']); $WorkersComp = ($trimmed['WorkersComp']); $InternetLiability = ($trimmed['InternetLiability']); $LifeDisability = ($trimmed['LifeDisability']); $ProductLiability = ($trimmed['ProductLiability']); $LegalLiability = ($trimmed['LegalLiability']); $PropertyContents = ($trimmed['PropertyContents']); $CargoMobileProperty = ($trimmed['CargoMobileProperty']); $EmployeeDishonesty = ($trimmed['EmployeeDishonesty']); $Retirement = ($trimmed['Retirement']); $Health = ($trimmed['Health']); $Other = ($trimmed['Other']); $Comments = ($trimmed['Comments']); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Tel)=="") $validationOK=false; if (Trim($State)=="") $validationOK=false; if (!validateEmail($EmailFrom)) $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Company: "; $Body .= $Company; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Website: "; $Body .= $Website; $Body .= "\n"; $Body .= "Employees: "; $Body .= $Employees; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Type of Business ====="; $Body .= "\n"; $Body .= "Manufacturer: "; $Body .= $Manufacturer; $Body .= "\n"; $Body .= "Retailer: "; $Body .= $Retailer; $Body .= "\n"; $Body .= "Jobber/Restyler: "; $Body .= $JobberRestyler; $Body .= "\n"; $Body .= "Distributor: "; $Body .= $Distributor; $Body .= "\n"; $Body .= "Motorsports: "; $Body .= $Motorsports; $Body .= "\n"; $Body .= "Professional Services: "; $Body .= $ProfessionalServices; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Insurance Needs ====="; $Body .= "\n"; $Body .= "General Liability: "; $Body .= $GeneralLiability; $Body .= "\n"; $Body .= "Garage/Keepers: "; $Body .= $GarageKeepers; $Body .= "\n"; $Body .= "Property Building: "; $Body .= $PropertyBuilding; $Body .= "\n"; $Body .= "Property Equipment: "; $Body .= $PropertyEquipment; $Body .= "\n"; $Body .= "Loss of Income: "; $Body .= $LossofIncome; $Body .= "\n"; $Body .= "Worker's Comp.: "; $Body .= $WorkersComp; $Body .= "\n"; $Body .= "Internet Liability: "; $Body .= $InternetLiability; $Body .= "\n"; $Body .= "Life & Disability: "; $Body .= $LifeDisability; $Body .= "\n"; $Body .= "Product Liability: "; $Body .= $ProductLiability; $Body .= "\n"; $Body .= "Legal Liability: "; $Body .= $LegalLiability; $Body .= "\n"; $Body .= "Property Contents: "; $Body .= $PropertyContents; $Body .= "\n"; $Body .= "Cargo/Mobile Property: "; $Body .= $CargoMobileProperty; $Body .= "\n"; $Body .= "Employee Dishonesty: "; $Body .= $EmployeeDishonesty; $Body .= "\n"; $Body .= "401K & Retirement: "; $Body .= $Retirement; $Body .= "\n"; $Body .= "Health: "; $Body .= $Health; $Body .= "\n"; $Body .= "Other: "; $Body .= $Other; $Body .= "\n"; $Body .= "\n"; $Body .= "Personal Comments: "; $Body .= $Comments; $Body .= "\n"; $Body .= "\n"; $Body .= "========================="; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1201319 Share on other sites More sharing options...
autoworld Posted April 13, 2011 Author Share Posted April 13, 2011 PS: the form still works well ... but still, when I type a pluralized word in the form field, e.g., "word's" it comes through with a "\" as "word\'s" ... I'd like that not to happen if possible. What did I miss? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1201322 Share on other sites More sharing options...
KevinM1 Posted April 14, 2011 Share Posted April 14, 2011 Remember to put your code inside tags. I did it for you above. Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1201380 Share on other sites More sharing options...
autoworld Posted April 14, 2011 Author Share Posted April 14, 2011 Okay, it all works as I'd hoped, with your assistance. One thing: I don't quite understand how to remove any instance of '\s coming back from form fields. I tried some things as you see below, but every instance where I put "test's" in a form field, it comes back as "test\'s" ... I am sure it's very simple, but it's over my head. Thanks to all for your assistance. ======================= <html> <head> <title>sendform</title> </head> <body> <?php function validateEmail($EmaiFrom){ $result = preg_match ("/^[^@ ]+@[^@ ]+\.[^@ \.]+$/", $EmaiFrom ); if ($result){ return true; }else{ return false; } } function TRIM_STRIP($string) { if( get_magic_quotes_gpc() === TRUE ) { $string = stripslashes($string); } $string = trim($string); $string = preg_replace('~[\s]{2,}~', ' ', $string); // Replace multiple spaces with one space, remove or comment out if not needed . . . return $string; } $trimmed = array_map('TRIM_STRIP', $_POST); // get posted data into local variables $EmailFrom = ($trimmed['EmailFrom']); $EmailTo = "bobp@autoworldmarketing.com, robertoprosser@gmail.com"; $Subject = "I need a quote"; $Name = ($trimmed['Name']); $Tel = ($trimmed['Tel']); $Company = ($trimmed['Company']); $State = ($trimmed['State']); $Website = ($trimmed['Website']); $Manufacturer = ($trimmed['Manufacturer']); $Retailer = ($trimmed['Retailer']); $JobberRestyler = ($trimmed777['JobberRestyler']); $Distributor = ($trimmed['Distributor']); $Motorsports = ($trimmed['Motorsports']); $ProfessionalServices = ($trimmed['ProfessionalServices']); $Employees = ($trimmed['Employees']); $GeneralLiability = ($trimmed['GeneralLiability']); $GarageKeepers = ($trimmed['GarageKeepers']); $PropertyBuilding = ($trimmed['PropertyBuilding']); $PropertyEquipment = ($trimmed['PropertyEquipment']); $LossofIncome = ($trimmed['LossofIncome']); $WorkersComp = ($trimmed['WorkersComp']); $InternetLiability = ($trimmed['InternetLiability']); $LifeDisability = ($trimmed['LifeDisability']); $ProductLiability = ($trimmed['ProductLiability']); $LegalLiability = ($trimmed['LegalLiability']); $PropertyContents = ($trimmed['PropertyContents']); $CargoMobileProperty = ($trimmed['CargoMobileProperty']); $EmployeeDishonesty = ($trimmed['EmployeeDishonesty']); $Retirement = ($trimmed['Retirement']); $Health = ($trimmed['Health']); $Other = ($trimmed['Other']); $Comments = ($trimmed['Comments']); // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Tel)=="") $validationOK=false; if (Trim($State)=="") $validationOK=false; if (!validateEmail($EmailFrom)) $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Company: "; $Body .= $Company; $Body .= "\n"; $Body .= "State: "; $Body .= $State; $Body .= "\n"; $Body .= "Website: "; $Body .= $Website; $Body .= "\n"; $Body .= "Employees: "; $Body .= $Employees; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Type of Business ====="; $Body .= "\n"; $Body .= "Manufacturer: "; $Body .= $Manufacturer; $Body .= "\n"; $Body .= "Retailer: "; $Body .= $Retailer; $Body .= "\n"; $Body .= "Jobber/Restyler: "; $Body .= $JobberRestyler; $Body .= "\n"; $Body .= "Distributor: "; $Body .= $Distributor; $Body .= "\n"; $Body .= "Motorsports: "; $Body .= $Motorsports; $Body .= "\n"; $Body .= "Professional Services: "; $Body .= $ProfessionalServices; $Body .= "\n"; $Body .= "\n"; $Body .= "===== Insurance Needs ====="; $Body .= "\n"; $Body .= "General Liability: "; $Body .= $GeneralLiability; $Body .= "\n"; $Body .= "Garage/Keepers: "; $Body .= $GarageKeepers; $Body .= "\n"; $Body .= "Property Building: "; $Body .= $PropertyBuilding; $Body .= "\n"; $Body .= "Property Equipment: "; $Body .= $PropertyEquipment; $Body .= "\n"; $Body .= "Loss of Income: "; $Body .= $LossofIncome; $Body .= "\n"; $Body .= "Worker's Comp.: "; $Body .= $WorkersComp; $Body .= "\n"; $Body .= "Internet Liability: "; $Body .= $InternetLiability; $Body .= "\n"; $Body .= "Life & Disability: "; $Body .= $LifeDisability; $Body .= "\n"; $Body .= "Product Liability: "; $Body .= $ProductLiability; $Body .= "\n"; $Body .= "Legal Liability: "; $Body .= $LegalLiability; $Body .= "\n"; $Body .= "Property Contents: "; $Body .= $PropertyContents; $Body .= "\n"; $Body .= "Cargo/Mobile Property: "; $Body .= $CargoMobileProperty; $Body .= "\n"; $Body .= "Employee Dishonesty: "; $Body .= $EmployeeDishonesty; $Body .= "\n"; $Body .= "401K & Retirement: "; $Body .= $Retirement; $Body .= "\n"; $Body .= "Health: "; $Body .= $Health; $Body .= "\n"; $Body .= "Other: "; $Body .= $Other; $Body .= "\n"; $Body .= "\n"; $Body .= "Personal Comments: "; $Body .= $Comments; $Body .= "\n"; $Body .= "\n"; $Body .= "========================="; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1201682 Share on other sites More sharing options...
KevinM1 Posted April 14, 2011 Share Posted April 14, 2011 This is the last time I fix your post. From now on, put your code inside tags. Example: // my code goes here You have been warned. Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1201691 Share on other sites More sharing options...
autoworld Posted April 14, 2011 Author Share Posted April 14, 2011 Hey Nightslyr, I'm really sorry about that ... I wasn't meaning to ignore you, I simply didn't understand what you meant ... I thought you meant put tags at the top and bottom of my actual coding, NOT when I post here. Quote Link to comment https://forums.phpfreaks.com/topic/233532-my-first-php-send-form-how-about-a-review-please/#findComment-1201700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.