...

View Full Version : Need some help, not a programmer, email submission script



Jack Corzine
08-18-2012, 05:00 PM
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 (http://ufp-squad.com/halfordmailtest/app_php.html) 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:


<?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
}
?>

If you require my html form code please let me know and I will post that as well. Thanks in advance.

Jack Corzine

AndrewGSW
08-19-2012, 02:16 AM
$signature = $_POST['signature1']; // not required

$email_message .= "Applicant signature: ".clean_string($signature1)."\n";

This should be corrected but it may not be enough to prevent the email being sent. It probably depends on your error-level settings.

Jack Corzine
08-19-2012, 02:35 AM
did not fix it but I thank you for finding that omission. Still not sure what is wrong. Do you need the html posted as well? Would that be helpful?

Jack

low tech
08-19-2012, 03:16 AM
Hi


I am not getting the email to send

I added an else check

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}else{echo "Email NOT posted!";}
?>

and found that you are checking for

if(isset($_POST['email']))

and

$email_from = $_POST['email'];

But in your HTML form (test bed above) you are not sending a name=email

This is the only email I can see in your form
<input type="text" name="co_emp_email" maxlength="30" size="30">

I think you need to check all your form posts

These are being posted.

name
date_of_birth
drivers_license
telephone
address1
city1
state1
zip_code1
current_monthly
how_long
number_residents
pets
employer
emp_address
how_long2
city2
state2
zip_code2
phone2
supervisor
position
income
emerg_name
emerg_address
emerg_city
emerg_state
emerg_zip_code
emerg_relation
co_name
co_date_of_birth
co_drivers_license
co_telephone
co_address1
co_city1
co_state1
co_zip_code1
co_employer
co_emp_address
co_emp_how_long
co_emp_city
co_emp_state
co_emp_zip_code1
co_emp_phone
co_emp_email
co_emp_fax
co_position
co_income
ref_name1
ref_address1
ref_phone1
ref_name2
ref_address2
ref_phone2
ref_name3
ref_address3
ref_phone3
bankrupt
evicted
authorize
signature1
date1
signature2
date2

LT



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum