Search the Community
Showing results for tags 'php mailing'.
-
I have a form that processes through php and mails me the information input from the form. The problem is when anyone inputs anything with a ' like I'm the mailed output looks like I/'m. I would like to know how to do this. Sorry if this is to simple but I'm a php newb. The code looks like this: <?php if(isset($_POST['element_4'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "kxxxxxxxxxxxxxxxxxxxxx"; $email_subject = "Computer Donation Application"; 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['element_1_1']) || !isset($_POST['element_1_2']) || !isset($_POST['element_4']) || !isset($_POST['element_3_1']) || !isset($_POST['element_3_2']) || !isset($_POST['element_3_3']) || !isset($_POST['element_2_1']) || !isset($_POST['element_2_2']) || !isset($_POST['element_2_3']) || !isset($_POST['element_2_4']) || !isset($_POST['element_2_5']) || !isset($_POST['element_7']) || !isset($_POST['element_8']) || !isset($_POST['element_5']) || !isset($_POST['element_6'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $element_1_1 = $_POST['element_1_1']; // required name first $element_1_2 = $_POST['element_1_2']; // required name second $element_2_1 = $_POST['element_2_1']; // not required address $element_2_2 = $_POST['element_2_2']; // not required address second $element_2_3 = $_POST['element_2_3']; // not required city $element_2_4 = $_POST['element_2_4']; // not required state $element_2_5 = $_POST['element_2_5']; // not required zip $element_4 = $_POST['element_4']; // required email $element_3_1 = $_POST['element_3_1']; // not required telephone $element_3_2 = $_POST['element_3_2']; // not required telephone $element_3_3 = $_POST['element_3_3']; // not required telephone $element_7 = $_POST['element_7']; if ($element_7 == '1'){ $element_7 = 'less than $8,000 dollars'; } elseif ($element_7 == '2'){ $element_7 = '$8,001 through $13,000'; } elseif ($element_7 == '3'){ $element_7 = '$13,001 through $20,000'; } else { $element_7 = 'over $20,000'; }// not required income level $element_8 = $_POST['element_8']; if ($element_8 == '1'){ $element_8 = 'Individual'; } elseif ($element_8 == '2'){ $element_8 = 'Business'; } else { $element_8 = 'Other Type'; } // not required application type $element_5 = $_POST['element_5']; // required need $element_6 = $_POST['element_6']; // required comments $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$element_4)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$element_1_1)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$element_1_2)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($element_5) < 2) { $error_message .= 'The Reason you entered does not appear to be valid.<br />'; } if(strlen($element_6) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Request For Computer Donation: Donation Form Graves IT Site\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($element_1_1)."\n\n"; $email_message .= "Last Name: ".clean_string($element_1_2)."\n\n"; $email_message .= "Customer Address 1: ".clean_string($element_2_1)."\n\n"; $email_message .= "Customer Address 2: ".clean_string($element_2_2)."\n\n"; $email_message .= "Customer City: ".clean_string($element_2_3)."\n\n"; $email_message .= "Customer State: ".clean_string($element_2_4)."\n\n"; $email_message .= "Customer Zip: ".clean_string($element_2_5)."\n\n"; $email_message .= "Customer Email: ".clean_string($element_4)."\n\n"; $email_message .= "Customer Telephone: ".clean_string($element_3_1)."-"; $email_message .= "".clean_string($element_3_2)."-"; $email_message .= "".clean_string($element_3_3)."\n\n"; $email_message .= "Customer Income Level: ".clean_string($element_7)."\n\n"; $email_message .= "Applicant Type: ".clean_string($element_."\n\n"; $email_message .= "Reason Computer Needed: ".clean_string($element_5)."\n\n"; $email_message .= "Comments or Other: ".clean_string($element_6)."\n\n"; // create email headers $headers = 'From: '.$element_4."\r\n". 'Reply-To: '.$element_4."\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. Your Application Has Been Accepted. <?php } ?>