<?php 
// print_r($_POST);exit();
$error="";

if(!isset($_POST['name']) || $_POST['name']=="")
{
	$error .="\nName is required";
}

else
{
	if(!preg_match('/^[a-zA-Z\\s]*$/',$_POST['name']))
	{
		$error .="\nEnter valid Name";
	}
}

if(!isset($_POST['cname']) || $_POST['cname']=="")
{
	$error .="\nName is required";
}

else
{
	if(!preg_match('/^[a-zA-Z\\s]*$/',$_POST['cname']))
	{
		$error .="\nEnter valid Company Name";
	}
}



if(!isset($_POST['email']) || $_POST['email']=="")
{
	$error .=" \nEmail Id is required";
}
else
{
	if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) 
	{	
	
		$error .=" \nEnter valid Email Id";
	}
}

if(!isset($_POST['phone']) || $_POST['phone']=="")
{
	$error .="\Phone no is required";
}

if(!isset($_POST['message']) || $_POST['message']=="" || trim($_POST['message'])=="")
{
	$error .=" \nMessage is required";
}

if ($error == "") {
    // Set up email headers
    $headers = "From: info@uniquedosingpumps.com\r\n";
    $headers .= "Bcc:backupilogicx@gmail.com\r\n"; // Add BCC recipient
    
    // Set content type
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    // Compose email message
    $message = "<html><body><table border='5px'>";
    $message .= "<tr><td colspan='2' style='color: #C50B33; font-size: 20px;'><b>Request For Contact</b></td></tr>";
   
    $message .= "<tr><td>Full Name: </td><td>" . $_POST['name'] . "</td></tr>";
      $message_body.="<tr><td>Contact's Company Name : </td><td>".$_POST['cname']."</td></tr>";
    $message .= "<tr><td>Email: </td><td>" . $_POST['email'] . "</td></tr>";
 
    $message .= "<tr><td>Phone: </td><td>" . $_POST['phone'] . "</td></tr>";
       $message .= "<tr><td>Address: </td><td>" . $_POST['address'] . "</td></tr>";
    $message .= "<tr><td>Message: </td><td>" . $_POST['message'] . "</td></tr>";
    $message .= "</table></body></html>";

   // Email recipient and subject
   $to = "sales@uniquedosing.com";
    $subject = "Contact For Uniquedosingpumps.com";
   
    // Send the email
    if (mail($to, $subject, $message, $headers)) {
        echo "sent";
    } else {
        echo "Sorry, an error occurred while sending your mail. Please try again.";
    }

    // Send a confirmation email to the user
    $user_subject = "Thank You For Your Message";
    $user_message = "Thank you for contacting us. We will get back to you soon.";
    $user_headers = "From: info@uniquedosingpumps.com\r\n";
    mail($_POST['email'], $user_subject, $user_message, $user_headers);


} else {
    echo $error;
}
?>