Advertisement
Guest User

Untitled

a guest
Oct 31st, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.98 KB | None | 0 0
  1. <?php
  2.         //If the user has submitted the form
  3.         if(isset($_POST['submit'])){
  4.                         //for connecting to MySql DB
  5.             require "./connect.php";
  6.             //protect and then add the posted data to variables
  7.  
  8.             $email = mysql_real_escape_string($_POST['email']);
  9.             $subject = mysql_real_escape_string($_POST['subject']);
  10.             $message = mysql_real_escape_string($_POST['message']);
  11.  
  12.             if(!$email || !$message){
  13.                 //if any weren't display the error message
  14.                 echo "<div class='alert alert-block alert-error'>
  15.                          <a class='close' data-dismiss='alert' href='#'>X</a>
  16.                          <h4 class='alert-heading'>Error!</h4>
  17.                           You need to fill in at least your email id and your message
  18.                     </div>";
  19.                
  20.             }else{
  21.                        
  22.                         $checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
  23.        
  24.                         //check if the formats match
  25.                         if(!preg_match($checkemail, $email)){
  26.                             //if not display error message
  27.                             echo "<div class='alert alert-block alert-error'>
  28.                                  <a class='close' data-dismiss='alert' href='#'>X</a>
  29.                                  <h4 class='alert-heading'>Error!</h4>
  30.                                   <b>E-mail</b> is not valid, must be something@server.com!
  31.                             </div>";
  32.                        
  33.                         }else{     
  34.                                 $adminemail = "myadmin@adminserver.com"; // THIS is the admin mail ID on which the message will go saying that this guy has has contacted you with this message
  35.                                 mail($adminemail,"Contact us mail from ".$email , "This guy ---> ".$email.",\n\nhas mailed you with the subject =".$subject.",\n\nand here is the message =".$message, 'From: noreply@adminsomething.com');
  36.  
  37.                                 //display the success message
  38.                                 echo "<div class='alert alert-block alert-success'>
  39.                                          <a class='close' data-dismiss='alert' href='#'>X</a>
  40.                                          <h4 class='alert-heading'>Message Sent Successfully</h4>
  41.                                          Thanks for contacting us.We will get back to you soon..
  42.                                      </div>";
  43.                                         session_destroy();
  44.                                     }
  45.                                 }                                          
  46.                             }
  47.  
  48.         ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement