Jump to content

help with email form


toney
Go to solution Solved by toney,

Recommended Posts

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 = "support@higherpowercomputers.com";
    $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_8)."\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
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.