Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // In response to question on Yahoo Answer's
- /* Functions */
- function validateEmail($i){
- //http://www.iamcal.com/publish/articles/php/parsing_email/
- $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
- $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
- $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
- '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
- $quoted_pair = '\\x5c[\\x00-\\x7f]';
- $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
- $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
- $domain_ref = $atom;
- $sub_domain = "($domain_ref|$domain_literal)";
- $word = "($atom|$quoted_string)";
- $domain = "$sub_domain(\\x2e$sub_domain)*";
- $local_part = "$word(\\x2e$word)*";
- $addr_spec = "$local_part\\x40$domain";
- return (strrpos($i,'.') > strrpos($i,'@'))? preg_match("!^$addr_spec$!", $i) : false;
- }
- function rfv(){ // Required Form Inputs
- $a = func_get_args();
- $cn = func_num_args();
- for($i=0; $i<$cn; ++$i){
- if(!isset($_POST[$a[$i]]{0})){
- return false;
- }
- }
- }
- 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.";
- exit;
- }
- function clean_string($string) {
- $bad = array("content-type","bcc:","to:","cc:","\r\n","\r","\n");
- return str_replace($bad,"",$string);
- }
- /* Start of the Form Processing */
- if(isset($_POST['email'])) {
- // CHANGE THE TWO LINES BELOW
- $email_to = "sales@thebusinessupgrades.com";
- $email_subject = "Order Forms";
- $_POST = array_map('trim', $_POST);
- // validation expected data exists
- if( !rfv('first_name','last_name','email','Name of Company','Colors','Target Audience','comments')) { // Required Form Inputs
- died('We are sorry, but there appears to be some missing form fields.');
- }
- $first_name = $_POST['first_name']; // required
- $last_name = $_POST['last_name']; // required
- $email_from = $_POST['email']; // required
- $telephone = $_POST['telephone']; // not required
- $name_of_company = $_POST['name_of_company']; // required
- $Colors = $_POST['Colors']; // required
- $target_audience = $_POST['target_audience']; // required
- $comments = $_POST['comments']; // required
- /* Error Checking */
- $error_message = "";
- if(!validateEmail($email_from)) {
- $error_message .= 'The Email Address you entered does not appear to be valid.<br>';
- }
- if(!preg_match( "/^[A-Za-z .'-]+$/", $first_name . ' ' . $last_name)) {
- $error_message .= 'The First or Last Name you entered appears to contain invalid characters.<br>'; // Althought this will fail against "foreign" names
- }
- if(!isset($comments{2})) {
- $error_message .= 'The Comments you entered do not appear to be valid.<br>';
- }
- if(strlen($error_message) > 0) {
- died($error_message);
- }
- $email_message = "Form details below.\n\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_from)."\n";
- $email_message .= "Telephone: ".clean_string($telephone)."\n";
- $email_message .= "Name of Company: ".clean_string($name_of_company)."\n";
- $email_message .= "Colors: ".clean_string($Colors)."\n";
- $email_message .= "target_audience: ".clean_string($target_audience)."\n";
- $email_message .= "Comments: ".clean_string($comments)."\n";
- // create email headers
- $headers = 'From: ' . $email_from . "\r\n";
- 'Reply-To: ' . $email_from . "\r\n" .
- 'X-Mailer: PHP/' . phpversion();
- if(!@mail($email_to, $email_subject, $email_message, $headers)){
- die('The mail could not be sent due to an internal error. Please try again later.');
- }
- }
- ?>
- <!-- place your own success html below -->
- Thank you for for choosing the Business Upgrades!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement