<?php
include("../connection.php");

if(isset($_POST['subscribe_form']))
{       
        //Check
        $email= $_POST["email"]; 
        $sql_check = "SELECT * FROM `tbl_news_letter` WHERE `news_letter_email`='$email'";
        $runNew = mysqli_query($link,$sql_check);
        if(mysqli_num_rows($runNew)==0)
        {
                  $ToEmail = 'abhayfivedesign@gmail.com';  // To Send Mail Id 
                  $Subject = "Newsletter.....!!!";
                  $mailheader = 'From : '.$_POST['email'].'\r\n'; 
                  $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
                  $mailheader = "MIME-Version: 1.0" . "\r\n";
                  $mailheader .= "Content-type:text/html;charset=UTF-8"."\r\n"; 
                  @$MESSAGE_BODY .= "Newsletter Id: ".$_POST["email"]."<br>";
                  @$MESSAGE_BODY .= "Email : ".$_POST["email"]."<br>";
                  
                  if(@mail($ToEmail, $Subject, $MESSAGE_BODY, $mailheader))
                  {
                    
                    $insert = "INSERT INTO `tbl_news_letter`(`news_letter_email`) VALUES ('$email')";
                    if(mysqli_query($link,$insert))
                     {
                      echo "Successfully Newsletter Send!!!";
                     }
                  }
                  else
                  {
                    
                    $insert = "INSERT INTO `tbl_news_letter`(`news_letter_email`) VALUES ('$email')";
                    if(mysqli_query($link,$insert))
                     {
                      echo "Newsletter Not Send!!!";
                     }
                    
                  } 
            } 
        else
        {
          //echo "Newsletter Not Send!!!";
          echo "You are Already Subscribed to Our Newsletter";  
        }
        
  
}
//Contact Form
if(isset($_POST['contact_form']))
{
 
        extract($_POST);
        $ToEmail = 'abhayfivedesign@gmail.com';   
        $Subject = $enq_con;       
        $mailheader = 'From : '.$email.'\r\n'; 
        $mailheader .= "Reply-To: ".$email."\r\n";
        $mailheader = "MIME-Version: 1.0" . "\r\n";
        $mailheader .= "Content-type:text/html;charset=UTF-8"."\r\n";
        @$MESSAGE_BODY .= "Name : ".$name."<br>";
        @$MESSAGE_BODY .= "Email : ".$email."<br>";
        @$MESSAGE_BODY .= "Subject : ".$phone."<br>";              
        @$MESSAGE_BODY .= "Message : ".$message."<br>";
        
        if(@mail($ToEmail, $Subject, $MESSAGE_BODY, $mailheader))
        {
          $sql_insert ="INSERT INTO `tbl_contact`(`name`, `email`, `phone_number`, `msg_subject`, `message`, `type`) VALUES ('$name','$email','$phone','$subject','$message','$type')";
          if(mysqli_query($link,$sql_insert))
          {
               echo "Successfully Mail Send!!!";
          } 
        	
        }
        else
        {
        	$sql_insert ="INSERT INTO `tbl_contact`(`name`, `email`, `phone_number`, `msg_subject`, `message`,`type`) VALUES ('$name','$email','$phone','$subject','$message','$type')";          
          if(mysqli_query($link,$sql_insert))
          {
               echo "Mail Not Send!!!";
          }          
        }
  
}

if(isset($_POST['contact_form_rr']))
{
        // echo "<pre>";
        // print_r($_POST);
        $ToEmail = 'abhayfivedesign@gmail.com';  // To Send Mail Id 
        $Subject = $_POST['enq_con']; 
        $me=$_POST['Fname']." ".$_POST['Lname'];      
        $mailheader = 'From : '.$_POST['email'].'\r\n'; 
        $mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
        $mailheader = "MIME-Version: 1.0" . "\r\n";
        $mailheader .= "Content-type:text/html;charset=UTF-8"."\r\n";

        @$MESSAGE_BODY .= "Name : ".$me."<br>";
        @$MESSAGE_BODY .= "Email : ".$_POST["email"]."<br>";
        @$MESSAGE_BODY .= "Phone : ".$_POST["phone"]."<br>";        
        @$MESSAGE_BODY .= "Service : ".$_POST["Service"]."<br>";
        @$MESSAGE_BODY .= "Subject : ".$_POST["subject"]."<br>";              
        @$MESSAGE_BODY .= "Message : ".$_POST["message"]."<br>";
        
        if(@mail($ToEmail, $Subject, $MESSAGE_BODY, $mailheader))
        {
            echo "Successfully Mail Send!!!".$me;
        }
        else
        {
            
          echo "Mail Not Send!!!".$me;
        }
}
?>