<?php

function limpiar($string ){
 $string = preg_replace('(\<(/?[^\>]+)\>)', '', $string);
 return $string;
}


$adminemail = "agra0809@gmail.com";
$ccp1 = "";
$cco = "";


	$username = limpiar($_POST['username']);
	$mail = $_POST['email'];
	$phone = limpiar($_POST['phone']);
	$institution = limpiar($_POST['institucion']);
	$state = limpiar($_POST['state']);
	$message	=	limpiar($_POST['message']);


/*echo $nombre;
echo $mail;
echo $tel;
echo $mje;*/






$mail_caract = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/";




	if($username=="" || $mail=="" || $phone=="" || $institution=="" || $state=="" || $message=="" )
	{
		echo 1;
	}
	elseif(!preg_match($mail_caract, $mail)){


		echo 2;

	}else{



									$headers .= "X-Sender: ".$adminemail."\n";

									$headers .= "X-Priority: 1\n";

									$headers .='x-mailer: php/' . phpversion() . "\r\n";

									$headers .= "X-Mailer: PHP - \n";

									$headers = "MIME-Version: 1.0\r\n" ;

									  $headers .= "Content-Type: text/html; charset=utf-8\n"; // Mime type

									$headers .= "From: ".$mail."\nReply-To:".$mail."\n";



									$tema= "Te han contactado desde " ;

									$mensaje="
									<table width='50%' border='0' align='center' >
									  <tbody>
										<tr>
										  <td style='font-weight:600; color: #000; text-align: left; font-size:14px;'>Nombre: <span style='color: #000'>".$name."</span></td>
										</tr>
										<tr>
											<td style='font-weight:600; color: #000; text-align: left; font-size:14px;'>Email: <span style='color: #000'>".$mail."</span></td>
										</tr>
										<tr>
                                        	<td style='font-weight:600; color: #000; text-align: left; font-size:14px;'>Teléfono: <span style='color: #000'>".$phone."</span></td>
                                        </tr>
                                        <tr>
                                        	<td style='font-weight:600; color: #000; text-align: left; font-size:14px;'>Nombre de la Institución: <span style='color: #000'>".$institute."</span></td>
                                        </tr>
                                        <tr>
                                        	<td style='font-weight:600; color: #000; text-align: left; font-size:14px;'>Estado o Ciudad: <span style='color: #000'>".$state."</span></td>
                                        </tr>
										<tr>
										  <td style='font-weight:600; color: #000; text-align: left; font-size:14px;'>Mensaje: <span style='color: #000'>".$message."</span></td>
										</tr>
                                        
									  </tbody>
									</table>
									";
									mail($adminemail,$tema,$mensaje,$headers); 
									mail($ccp1,$tema,$mensaje,$headers);
									mail($ccp2,$tema,$mensaje,$headers);
									mail($cco,$tema,$mensaje,$headers);
										 echo 0;



}




?>