toney Posted August 30, 2013 Share Posted August 30, 2013 i wrote the following code but it keeps giving me an error on the first name and the email please help <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Video Rental Form"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$company_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "ALL ABOUT GUCA: ".clean_string($video_1)."\n"; $email_message .= "AMERICA IN JEOPARDY: ".clean_string($video_2)."\n"; $email_message .= "AS EASY AS A PHONE CALL: ".clean_string($video_3)."\n"; $email_message .= "AUGER BORING OPERATIONS: ".clean_string($video_4)."\n"; $email_message .= "BUILD IT: ".clean_string($video_5)."\n"; $email_message .= "CALL BEFORE YOU DIG: ".clean_string($video_6)."\n"; $email_message .= "CNA INSURANCE: ".clean_string($video_7)."\n"; $email_message .= "COMMON GROUND IN DAMAGE PREVENTION: ".clean_string($video_."\n"; $email_message .= "CONFINED SPACE ENTRY: ".clean_string($video_9)."\n"; $email_message .= "CONSOLIDATED INDUSTRY SAFETY: ".clean_string($video_10)."\n"; $email_message .= "CONSTRUCTION DEMO: ".clean_string($video_11)."\n"; $email_message .= "DIGGING DANGERS I: ".clean_string($video_12)."\n"; $email_message .= "DIGGING DANGERS III: ".clean_string($video_13)."\n"; $email_message .= "DIGGING DANGERS V: ".clean_string($video_14)."\n"; $email_message .= "DIGGING DANGERS VI: ".clean_string($video_15)."\n"; $email_message .= "DIG SAFELY: ".clean_string($video_16)."\n"; $email_message .= "ELECTRICITY: ".clean_string($video_17)."\n"; $email_message .= "GET THE DIRT: ".clean_string($video_18)."\n"; $email_message .= "HAMMERHEAD MOLE PIPE BURSTING: ".clean_string($video_19)."\n"; $email_message .= "HAND SIGNALS FOR CONSTRUCTION EQUIPMENT : ".clean_string($video_20)."\n"; $email_message .= "HEADACHES FOR VANDALS: ".clean_string($video_21)."\n"; $email_message .= "HEAVY EQUIPMENT OPERATIONS: ".clean_string($video_22)."\n"; $email_message .= "HORIZONTAL DIRECTIONAL DRILLING: ".clean_string($video_23)."\n"; $email_message .= "HOW FAR DO YOU WANT TO GO?: ".clean_string($video_24)."\n"; $email_message .= "INSTALLING: PRESTRESSED CONCRETE CYLINDER PIPE: ".clean_string($video_25)."\n"; $email_message .= "IT'S WHERE SAFE DIGGING STARTS: ".clean_string($video_26)."\n"; $email_message .= "MANUFACTURING: ".clean_string($video_27)."\n"; $email_message .= "NATIONAL UTILITY CONTRACTORS ASSOCIATION: ".clean_string($video_28)."\n"; $email_message .= "NUTS AND BOLTS OF TRENCH PROTECTIVE SYSTEMS: ".clean_string($video_29)."\n"; $email_message .= "PIPE AND CABLE LOCATOR: ".clean_string($video_30)."\n"; $email_message .= "PIPE HANDLING: ".clean_string($video_31)."\n"; $email_message .= "POWERFUL FORCES: ".clean_string($video_32)."\n"; $email_message .= "PRACTICAL BLASTING FUNDAMENTALS: ".clean_string($video_33)."\n"; $email_message .= "PROTECTIVE EQUIPMENT: ".clean_string($video_34)."\n"; $email_message .= "PROTECTIVE SYSTEMS: ".clean_string($video_35)."\n"; $email_message .= "REAL JOBS FOR REAL PEOPLE: ".clean_string($video_36)."\n"; $email_message .= "SAFE & EFFICIENT OPERATION OF HAND HELD SAWS: ".clean_string($video_37)."\n"; $email_message .= "SAFETY IN FLAGGING: ".clean_string($video_38)."\n"; $email_message .= "SAFETY TRAINING FOR REPAIR TECHS: ".clean_string($video_39)."\n"; $email_message .= "SEEING lS BELIEVING: ".clean_string($video_40)."\n"; $email_message .= "SOQUE DIARY: ".clean_string($video_41)."\n"; $email_message .= "STEALING FROM THIEVES: ".clean_string($video_42)."\n"; $email_message .= "SURVIVAL EXCAVATION: ".clean_string($video_43)."\n"; $email_message .= "TAPPING: ".clean_string($video_44)."\n"; $email_message .= "TELEPHONE COURTESY: ".clean_string($video_45)."\n"; $email_message .= "THE FUTURE IS NOW: ".clean_string($video_46)."\n"; $email_message .= "TRAILER TRANSPORT SAFETY: ".clean_string($video_47)."\n"; $email_message .= "TRENCH SHIELDS: ".clean_string($video_48)."\n"; $email_message .= "TRENCH SHORING: ".clean_string($video_49)."\n"; $email_message .= "TRENCHING SAFETY: ".clean_string($video_50)."\n"; $email_message .= "TRENCHING SAFETY II: ".clean_string($video_51)."\n"; $email_message .= "TRYING TO MAKE SENSE OF YOUR FUTURE: ".clean_string($video_52)."\n"; $email_message .= "TUNNELING SAFETY: ".clean_string($video_53)."\n"; $email_message .= "WE DIG SAFETY: ".clean_string($video_54)."\n"; $email_message .= "Company Name: ".clean_string($company_name)."\n"; $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Address: ".clean_string($address)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "State: ".clean_string($state)."\n"; $email_message .= "Zip Code: ".clean_string($zip_code)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> Link to comment https://forums.phpfreaks.com/topic/281714-help-with-email-form/ Share on other sites More sharing options...
Psycho Posted August 31, 2013 Share Posted August 31, 2013 if(!preg_match($email_exp,$email)) { $email is not defined. The error you are getting with the first name has nothing to do with the first name. it is because of this: if(!preg_match($string_exp,$company_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } $company_name is not defined causing this validation to fail, but the error message states "first name" Link to comment https://forums.phpfreaks.com/topic/281714-help-with-email-form/#findComment-1447488 Share on other sites More sharing options...
toney Posted August 31, 2013 Author Share Posted August 31, 2013 ok I got the email and the company name errors fixed. Link to comment https://forums.phpfreaks.com/topic/281714-help-with-email-form/#findComment-1447560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.