* Required field"); define("ERR_INVALID", " * Invalid entry"); // array to hold errors for each field $errors = array("firstname" => "", "lastname" => "", "address" => "", "city" => "", "state" => "", "zipcode" => "", "phone" => "", "email" => "", "available" => "", "message" => "", "file" => ""); $headerpic="banner-right.gif"; include("inc/top.php4"); $fileatt = $_FILES['file']['tmp_name']; $fileatt_type = $_FILES['file']['type']; $fileatt_name = $_FILES['file']['name']; echo "
"; echo "
"; echo "
"; echo "

Job title: ".$_GET['job_title']."

"; echo "

Date: ".date("m/d/y")."

"; if(form_complete($errors)) { // if form is ok => send the email send_mail($fileatt, $fileatt_type, $fileatt_name); } else { // else (re)print form with error messages print_form($errors); } echo "
"; include("inc/bottom.php4"); function form_complete(&$errors) { $i = 0; // error count if ($_SERVER['REQUEST_METHOD']=="POST") { // check errors only if user POSTs if (empty($_POST['firstname'])) { $errors["firstname"] = ERR_EMPTY; $i++; } if (empty($_POST['lastname'])) { $errors["lastname"] = ERR_EMPTY; $i++; } if (empty($_POST['address'])) { $errors["address"] = ERR_EMPTY; $i++; } if (empty($_POST['city'])) { $errors["city"] = ERR_EMPTY; $i++; } if (empty($_POST['state'])) { $errors["state"] = ERR_EMPTY; $i++; } if (empty($_POST['zipcode'])) { $errors["zipcode"] = ERR_EMPTY; $i++; } if (empty($_POST['phone'])) { $errors["phone"] = ERR_EMPTY; $i++; } elseif (!valid_phone($_POST['phone'])) { $errors["phone"] = ERR_INVALID; $i++; } if (empty($_POST['email'])) { $errors["email"] = ERR_EMPTY; $i++; } elseif (!valid_email($_POST['email'])) { $errors["email"] = ERR_INVALID; $i++; } if (empty($_POST['available'])) { $errors["available"] = ERR_EMPTY; $i++; } if (empty($_POST['message'])) { $errors["message"] = ERR_EMPTY; $i++; } if (empty($_FILES['file']['name'])) { $errors["file"] = ERR_EMPTY; $i++; } if ($i == 0){ // if no errors, form is complete return true; } else { return false; } } else { // assume form is incomplete if no POST return false; } } function valid_phone($phone) { // format: xxx-xxx-xxxx $regex = '^[2-9][0-9]{2}-[2-9][0-9]{2}-[0-9]{4}$'; if (ereg($regex, $phone)) { return true; } else { return false; } } function valid_email($email) { // format: xxx@xxx.xxx $regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$'; if (eregi($regex, $email)) { return true; } else { return false; } } function print_form($errors) { // prints form and errors (if any) echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo "\n"; echo "
\n
\n"; } function send_mail($fileatt, $fileatt_type, $fileatt_name) { // build and send email $email_from = "Jobs@Paynecorp.com"; $email_subject = "App: ".$_GET['job_title']; $email_message = "
" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "
Position".$_GET['job_title']."
Date".date("m/d/y")."
Name".$_POST['firstname']." ".$_POST['lastname']."
Address".$_POST['address']."
".$_POST['city'].", ".$_POST['state']." ".$_POST['zipcode']."
Phone".$_POST['phone']."
Email".$_POST['email']."
Date Available".$_POST['available']."
Message".$_POST['message']."
"; $email_to = TO; $headers = "From: ".$email_from; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n"; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; $ok = @mail($email_to, $email_subject, $email_message, $headers); if ($ok) { echo "

Your application has been sent. Thank you for your interest in Payne Environmental.





"; } else { echo "

Application could not be sent. Please email your resume to jobs@paynecorp.com.





"; } } ?>