<?php
	$error = false;
	$nombre = $_POST['nombre'];
	$email = $_POST['email'];
	$texto = $_POST['consulta'];	

	/*if (empty($name)) $error = true;
	if (empty($email)) $error = true;
    if (empty($texto)) $error = true;*/

    if ($error == false) {
        if(isset($email)) {
            if (preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i',trim($email))) {
            } else {
                $error = true;
            }
            $ok = TRUE;
            $ok = eregi( "^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$", $email, $check);
            $ok = getmxrr(substr(strstr($check[0], '@'), 1), $dummy);
            if($ok === false) {
                $host = substr($email, strpos($email, '@') + 1);
                if(gethostbyname($host) != $host) {
                    $ok = true;
                }
                if ($ok != true) {
                    $error = true;
                }
            }
        }
    }

    if ($error == false) {
		$para = 'intedimadrid@gmail.com';
    
		$header = 'From: ' . $email . " \r\n";
		$header .= 'To: ' . $para . " \r\n";		
		$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
		$header .= "Mime-Version: 1.0 \r\n";
		$header .= "Content-Type: text/plain";
		
		$msg = "------------------------------- \n";
		$msg.= "         Comentarios            \n";
		$msg.= "------------------------------- \n";
		$msg.= "NOMBRE:   ".$nombre."\n";
		$msg.= "EMAIL:    ".$email."\n";
		$msg.= "FECHA:    ".date("D, d M Y")."\n";
		$msg.= "HORA:     ".date("h:i:s a ")."\n";
		$msg.= "IP:       ".$REMOTE_ADDR."\n";
		$msg.= "------------------------------- \n\n";
		$msg.= $texto."\n\n";
		$msg.= "------------------------------- \n";

		$asunto = 'Mensaje desde página web de Intedi';
		
		mail($para, $asunto, utf8_decode($msg), $header);
		
		// Redirect
		header("Location: contacto_ok.html");
	}
	else {
		header("Location: contacto.html");	
	}
?>