RtThemesSupport

contact_form.php RT15

Mar 30th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.34 KB | None | 0 0
  1. <?php
  2. $your_email=trim($_POST['your_email']);
  3. $your_web_site_name=trim($_POST['your_web_site_name']);
  4. ?>
  5.  
  6. <?php
  7. //If the form is submitted
  8. if(isset($_POST['name'])) {
  9.  
  10.         //Check to make sure that the name field is not empty
  11.         if(trim($_POST['name']) === '') {
  12.             $hasError = true;
  13.         } else {
  14.             $name = trim($_POST['name']);
  15.         }
  16.        
  17.         //Check to make sure sure that a valid email address is submitted
  18.         if(trim($_POST['email']) === '')  {
  19.             $hasError = true;
  20.         } else if (!preg_match('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$^', trim($_POST['email']))) {
  21.             $hasError = true;
  22.             $errorMessage = $_POST['text_4'];
  23.         } else {
  24.             $email = trim($_POST['email']);
  25.         }
  26.  
  27.         //phone
  28.         if(isset($_POST['phone'])) $phone = trim($_POST['phone']);
  29.        
  30.         //company name
  31.         if(isset($_POST['company_name'])) $company_name = trim($_POST['company_name']);
  32.  
  33.         //company url
  34.         if(isset($_POST['company_url'])) $company_url = trim($_POST['company_url']);       
  35.            
  36.         //Check to make sure comments were entered 
  37.         if(trim($_POST['message']) === '') {
  38.             $hasError = true;
  39.         } else {
  40.             if(function_exists('stripslashes')) {
  41.                 $comments = stripslashes(trim($_POST['message']));
  42.             } else {
  43.                 $comments = trim($_POST['message']);
  44.             }
  45.         }
  46.  
  47.         //If there is no error, send the email
  48.         if(!isset($hasError)) {
  49.  
  50.             $emailTo = $your_email;
  51.  
  52.             $subject = 'Contact Form Submission from '.$name;
  53.            
  54.             //message body
  55.             $body  ="Name: $name \n\n";
  56.             $body .="Email: $email \n\n";
  57.             if(isset($phone)) $body .="Phone:$phone\n\n";
  58.             if(isset($company_name)) $body .="Company Name: $company_name\n\n";
  59.             if(isset($company_url)) $body .="Company Url: $company_url \n\n";
  60.             $body .="Message: $comments";
  61.  
  62.             $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email . "\n";
  63.             $headers .= "Content-Type: text/plain; charset=UTF-8\n";
  64.             $headers .= "Content-Transfer-Encoding: 8bit\n";
  65.            
  66.             mail($emailTo, $subject, $body, $headers);
  67.             $emailSent = true;
  68.         }
  69. }
  70. ?>
  71.  
  72. <?php if(isset($emailSent) == true) { ?>
  73.     <div class="ok_box">
  74.         <h3><?php echo $_POST['text_1'];?>, <?php echo $name;?></h3>
  75.         <p><?php echo $_POST['text_2'];?></p>
  76.     </div>
  77. <?php } ?>
  78.  
  79. <?php if(isset($hasError) ) { ?>
  80.     <div class="error_box">
  81.         <?php echo $_POST['text_3'];?>
  82.         <br />
  83.         <?php echo $errorMessage;?>
  84.     </div>
  85. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment