Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //If the user has submitted the form
- if(isset($_POST['submit'])){
- //for connecting to MySql DB
- require "./connect.php";
- //protect and then add the posted data to variables
- $email = mysql_real_escape_string($_POST['email']);
- $subject = mysql_real_escape_string($_POST['subject']);
- $message = mysql_real_escape_string($_POST['message']);
- if(!$email || !$message){
- //if any weren't display the error message
- echo "<div class='alert alert-block alert-error'>
- <a class='close' data-dismiss='alert' href='#'>X</a>
- <h4 class='alert-heading'>Error!</h4>
- You need to fill in at least your email id and your message
- </div>";
- }else{
- $checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
- //check if the formats match
- if(!preg_match($checkemail, $email)){
- //if not display error message
- echo "<div class='alert alert-block alert-error'>
- <a class='close' data-dismiss='alert' href='#'>X</a>
- <h4 class='alert-heading'>Error!</h4>
- <b>E-mail</b> is not valid, must be something@server.com!
- </div>";
- }else{
- $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
- 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');
- //display the success message
- echo "<div class='alert alert-block alert-success'>
- <a class='close' data-dismiss='alert' href='#'>X</a>
- <h4 class='alert-heading'>Message Sent Successfully</h4>
- Thanks for contacting us.We will get back to you soon..
- </div>";
- session_destroy();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement