html form and php submission

Discussion in 'Software' started by Shadowchaser, Aug 18, 2012.

  1. Shadowchaser

    Shadowchaser A Really Great Guy

    Hey guys,

    Been struggling with an email pre-authorization form (html based and being submitted via PHP). At first I tried a fillable PDF form but that did not work out as the only output I could get in IE and Chrome was in XML which my client does not want so I have reverted to PHP to handle the sending of the form and data. So, I have modified some code I found (which originally worked) but I am not getting the email to send. The url to the test bed is here so you can check it out and see that it does not create the email needed. I'm certain it is merely an error in the coding someplace (I think it is something to do with the error checking). I am not a PHP programmer and am requesting someone here to look at it and at least steer me in the right direction. I really need an answer fairly quick guys so please help out here. Here is the PHP code:

    Code:
    <?php
    if(isset($_POST['email'])) {
    
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "ironhead380@mchsi.com";
        $email_subject = "test of halford submission php ver.";
    
    
        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['name']) ||
            !isset($_POST['date_of_birth']) ||
            !isset($_POST['driver_license']) ||
            !isset($_POST['telephone']) ||
            !isset($_POST['address1']) ||
            !isset($_POST['city1']) ||
            !isset($_POST['state1']) ||
            !isset($_POST['zip_code1']) ||
            !isset($_POST['own']) ||
            !isset($_POST['rent']) ||
            !isset($_POST['current_monthly']) ||
            !isset($_POST['how_long']) ||
            !isset($_POST['number_residents']) ||
            !isset($_POST['pets']) ||
            !isset($_POST['employer']) ||
            !isset($_POST['emp_address']) ||
            !isset($_POST['how_long2']) ||
            !isset($_POST['city2']) ||
            !isset($_POST['state2']) ||
            !isset($_POST['zip_code2']) ||
            !isset($_POST['phone2']) ||
            !isset($_POST['supervisor']) ||
            !isset($_POST['position']) ||
            !isset($_POST['salary']) ||
            !isset($_POST['hourly']) ||
            !isset($_POST['income']) ||
            !isset($_POST['emerg_name']) ||
            !isset($_POST['emerg_address']) ||
            !isset($_POST['emerg_city']) ||
            !isset($_POST['emerg_state']) ||
            !isset($_POST['emerg_zip_code']) ||
            !isset($_POST['emerg_relation']) ||
            !isset($_POST['co_name']) ||
            !isset($_POST['co_date_of_birth']) ||
            !isset($_POST['co_drivers_license']) ||
            !isset($_POST['co_telephone']) ||
            !isset($_POST['co_address1']) ||
            !isset($_POST['co_city1']) ||
            !isset($_POST['co_state1']) ||
            !isset($_POST['co_zip_code1']) ||
            !isset($_POST['co_employer']) ||
            !isset($_POST['co_emp_address']) ||
            !isset($_POST['co_emp_how_long']) ||
            !isset($_POST['co_emp_city']) ||
            !isset($_POST['co_emp_state']) ||
            !isset($_POST['co_emp_zip_code1']) ||
            !isset($_POST['co_emp_phone']) ||
            !isset($_POST['co_emp_email']) ||
            !isset($_POST['co_emp_fax']) ||
            !isset($_POST['co_position']) ||
            !isset($_POST['co_salary']) ||
            !isset($_POST['co_hourly']) ||
            !isset($_POST['co_income']) ||
            !isset($_POST['ref_name1']) ||
            !isset($_POST['ref_address1']) ||
            !isset($_POST['ref_phone1']) ||
            !isset($_POST['ref_name2']) ||
            !isset($_POST['ref_address2']) ||
            !isset($_POST['ref_phone2']) ||
            !isset($_POST['ref_name3']) ||
            !isset($_POST['ref_address3']) ||
            !isset($_POST['ref_phone3']) ||
            !isset($_POST['bankrupt']) ||
            !isset($_POST['evicted']) ||
            !isset($_POST['authorize']) ||
            !isset($_POST['signature1']) ||
            !isset($_POST['date1']) ||
            !isset($_POST['signature2']) ||
            !isset($_POST['date2']) ||
            !isset($_POST['email'])) {
    
            died('We are sorry, but there appears to be a problem with the form you submitted.');
        }
    
        $name = $_POST['name']; // required
        $date_of_birth = $_POST['date_of_birth']; // required
        $driver_license = $_POST["driver_license"]; // required
        $email_from = $_POST['email']; // required
        $telephone = $_POST['telephone']; // not required
        $address1 = $_POST['address1']; // required
        $city1 = $_POST['city1']; // not required
        $state1 = $_POST['atate1']; // not required
        $zip_code1 = $_POST['zip_code1']; // not required
        $own = $_POST['own']; // not required
        $rent = $_POST['rent']; // not required
        $current_monthly = $_POST['current_monthly']; // not required
        $how_long = $_POST['how_long']; // not required
        $number_residents = $_POST['number_residents']; // not required
        $pets = $_POST['pets']; // not required
        $employer = $_POST['employer']; // not required
        $emp_address = $_POST['emp_address']; // not required
        $how_long2 = $_POST['how_long2']; // not required
        $city2 = $_POST['city2']; // not required
        $state2 = $_POST['state2']; // not required
        $zip_code2 = $_POST['zip_code2']; // not required
        $phone2 = $_POST['phone2']; // not required
        $supervisor = $_POST['supervisor']; // not required
        $position = $_POST['position']; // not required
        $salary = $_POST['salary']; // not required
        $hourly = $_POST['hourly']; // not required
        $income = $_POST['income']; // not required
        $emerg_name = $_POST['emerg_name']; // not required
        $emerg_address = $_POST['emerg_address']; // not required
        $emerg_city = $_POST['emerg_city']; // not required
        $emerg_state = $_POST['emerg_state']; // not required
        $emerg_zip_code = $_POST['emerg_zip_code']; // not required
        $emerg_relation = $_POST['emerg_relation']; // not required
        $co_name = $_POST['co_name']; // not required
        $co_date_of_birth = $_POST['co_date_of_birth']; // not required
        $co_drivers_license = $_POST['co_drivers_license']; // not required
        $co_telephone = $_POST['co_telephone']; // not required
        $co_address = $_POST['co_address']; // not required
        $co_city = $_POST['co_city']; // not required
        $co_state = $_POST['co_state']; // not required
        $co_zip_code = $_POST['co_zip_code']; // not required
        $co_employer = $_POST['co_employer']; // not required
        $co_emp_address = $_POST['co_emp_address']; // not required
        $co_emp_how_long = $_POST['co_emp_how_long']; // not required
        $co_emp_city = $_POST['co_emp_city']; // not required
        $co_emp_state = $_POST['co_emp_state']; // not required
        $co_emp_zip_code = $_POST['co_emp_zip_code']; // not required
        $co_emp_phone = $_POST['co_emp_phone']; // not required
        $co_emp_email = $_POST['co_emp_email']; // not required
        $co_emp_fax = $_POST['co_emp_fax']; // not required
        $co_position = $_POST['co_position']; // not required
        $co_hourly = $_POST['co_hourly']; // not required
        $co_salary = $_POST['co_salary']; // not required
        $co_income = $_POST['co_income']; // not required
        $ref_name1 = $_POST['ref_name1']; // not required
        $ref_address1 = $_POST['ref_address1']; // not required
        $ref_phone1 = $_POST['ref_phone1']; // not required
        $ref_name2 = $_POST['ref_name2']; // not required
        $ref_address2 = $_POST['ref_address2']; // not required
        $ref_phone2 = $_POST['ref_phone2']; // not required
        $ref_name3 = $_POST['ref_name3']; // not required
        $ref_address3 = $_POST['ref_address3']; // not required
        $ref_phone3 = $_POST['ref_phone3']; // not required
        $bankrupt = $_POST['bankrupt']; // not required
        $evicted = $_POST['evicted']; // not required
        $authorize = $_POST['authorize']; // not required
        $signature = $_POST['signature1']; // not required
        $date1 = $_POST['date1']; // not required
        $signature2 = $_POST['signature2']; // not required
        $date2 = $_POST['date2']; // not required
    
    
    
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$name)) {
        $error_message .= 'The Name you entered does not appear to be valid.<br />';
      }
      if(!preg_match($string_exp,$date_of_birth)) {
        $error_message .= 'The date of birth you entered does not appear to be valid.<br />';
      }
      if(strlen($address1) < 2) {
        $error_message .= 'The address you entered do 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 .= "Name: ".clean_string($name)."\n";
        $email_message .= "Date Of Birth: ".clean_string($date_of_birth)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Telephone: ".clean_string($telephone)."\n";
        $email_message .= "Address: ".clean_string($address)."\n";
        $email_message .= "City: ".clean_string($city1)."\n";
        $email_message .= "State: ".clean_string($state1)."\n";
        $email_message .= "Zip Code: ".clean_string($zip_code1)."\n";
        $email_message .= "Own: ".clean_string($own)."\n";
        $email_message .= "Rent: ".clean_string($rent)."\n";
        $email_message .= "How long: ".clean_string($how_long)."\n";
        $email_message .= "Number of residents: ".clean_string($number_residents)."\n";
        $email_message .= "Pets: ".clean_string($pets)."\n";
        $email_message .= "Employer: ".clean_string($employer)."\n";
        $email_message .= "Employers address: ".clean_string($emp_address)."\n";
        $email_message .= "How long: ".clean_string($how_long2)."\n";
        $email_message .= "Employer city: ".clean_string($city2)."\n";
        $email_message .= "Employer state: ".clean_string($state2)."\n";
        $email_message .= "Zip Code: ".clean_string($zip_code2)."\n";
        $email_message .= "Supervisor: ".clean_string($supervisor)."\n";
        $email_message .= "Position: ".clean_string($position)."\n";
        $email_message .= "Salary: ".clean_string($salary)."\n";
        $email_message .= "Hourly: ".clean_string($hourly)."\n";
        $email_message .= "Annual Income: ".clean_string($income)."\n";
        $email_message .= "Emergency Contact: ".clean_string($emerg_name)."\n";
        $email_message .= "Address: ".clean_string($emerg_address)."\n";
        $email_message .= "City: ".clean_string($emerg_city)."\n";
        $email_message .= "State: ".clean_string($emerg_state)."\n";
        $email_message .= "Zip Code: ".clean_string($emerg_zip_code)."\n";
        $email_message .= "Relation: ".clean_string($emerg_relation)."\n";
        $email_message .= "Co-Applicant: ".clean_string($co_name)."\n";
        $email_message .= "Date of birth: ".clean_string($co_date_of_birth)."\n";
        $email_message .= "Drivers License: ".clean_string($co_drivers_license)."\n";
        $email_message .= "Telephone: ".clean_string($co_telephone)."\n";
        $email_message .= "Address: ".clean_string($co_address)."\n";
        $email_message .= "City: ".clean_string($co_city)."\n";
        $email_message .= "State: ".clean_string($co_state)."\n";
        $email_message .= "Zip Code: ".clean_string($co_zip_code)."\n";
        $email_message .= "Employer: ".clean_string($co_employer)."\n";
        $email_message .= "Employer Address: ".clean_string($co_emp_address)."\n";
        $email_message .= "How long: ".clean_string($co_emp_how_long)."\n";
        $email_message .= "Employer City: ".clean_string($co_emp_city)."\n";
        $email_message .= "Employer State: ".clean_string($co_emp_state)."\n";
        $email_message .= "Employer Zip Code: ".clean_string($co_emp_zip_code)."\n";
        $email_message .= "Employer phone: ".clean_string($co_emp_phone)."\n";
        $email_message .= "Work email: ".clean_string($co_emp_email)."\n";
        $email_message .= "Fax: ".clean_string($co_emp_fax)."\n";
        $email_message .= "Position: ".clean_string($co_position)."\n";
        $email_message .= "Salary: ".clean_string($co_salary)."\n";
        $email_message .= "Hourly: ".clean_string($co_hourly)."\n";
        $email_message .= "Annual Income: ".clean_string($co_income)."\n";
        $email_message .= "Landlord refence: ".clean_string($ref_name1)."\n";
        $email_message .= "Landlord address: ".clean_string($ref_address1)."\n";
        $email_message .= "Landlord phone: ".clean_string($ref_phone1)."\n";
        $email_message .= "Landlord refence: ".clean_string($ref_name2)."\n";
        $email_message .= "Landlord address: ".clean_string($ref_address2)."\n";
        $email_message .= "Landlord phone: ".clean_string($ref_phone2)."\n";
        $email_message .= "Landlord refence: ".clean_string($ref_name3)."\n";
        $email_message .= "Landlord address: ".clean_string($ref_address3)."\n";
        $email_message .= "Landlord phone: ".clean_string($ref_phone3)."\n";
        $email_message .= "Have you filed for bankruptcy?: ".clean_string($bankrupt)."\n";
        $email_message .= "Have you ever been evicted: ".clean_string($evicted)."\n";
        $email_message .= "I authorize....: ".clean_string($authorize)."\n";
        $email_message .= "Applicant signature: ".clean_string($signature1)."\n";
        $email_message .= "Date: ".clean_string($date1)."\n";
        $email_message .= "Applicant signature: ".clean_string($signature2)."\n";
        $email_message .= "Date: ".clean_string($date2)."\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
    }
    ?>
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds