<?php
/*********** Sent Mail ***********/ 
add_action( 'wp_ajax_webhosty_sndadminmail', 'webhosty_sndadminmail' );
add_action( 'wp_ajax_nopriv_webhosty_sndadminmail', 'webhosty_sndadminmail' );
function webhosty_sndadminmail(){ 
	global $webh_data; 
	$message = '';
	$to = $webh_data['webhosty_contactemailadds'];//$webh_data['webhosty_contactemail']; 
	if(isset($_POST['name'])){
		$nm = $_POST['name'];
		$message .= "NAME : ".$_POST['name']."\n";
	}
	if(isset($_POST['email'])){
		$email = $_POST['email'];
		$message .= "EMAIL : ".$_POST['email']."\n";
	}
	if(isset($_POST['sub'])){
		$phone = $_POST['sub'];
		$message .= "NUMBER : ".$_POST['sub']."\n";
	}
	if(isset($_POST['category'])){
		$web = $_POST['category'];
		$message .= "Category : ".$_POST['category']."\n";
	}
	if(isset($_POST['message'])){ 
		$meg = $_POST['message'];
		$message .= "MESSAGE : ".$_POST['message'];
	}
    $message .= "\n\n";
	$host = $_SERVER['HTTP_HOST'];
	preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
	$header = "From: webhosty@".$matches[0]."\r\n";   
	$header.= "MIME-Version: 1.0\r\n"; 
	$header.= "Content-Type: text/plain; charset=utf-8\r\n"; 
	$header.= "X-Priority: 1\r\n"; 
	$sub = "Inquiry webhosty";
	if(isset($_POST['copyemail_check']))
		{		 
	mail($to,$sub,$message,$header); 
		mail($email,$sub,$message,$header);
		$meg = $webh_data['webhosty_successmessage']; 
		}
	elseif(mail($to,$sub,$message,$header)){
		$meg = $webh_data['webhosty_successmessage']; 
	}
	else{
		$meg = "Sorry. your mail has not been send successfully."; 
	}
	echo esc_attr($meg);
	die();
}
?>