<?php
function ValidateEmail($email)
{
   $pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
   return preg_match($pattern, $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form1')
{
   $mailto = 'contacto@mail.com';
   $mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
   $subject = 'Contacto Web';
   $message = 'Values submitted from web site form:';
   $success_url = './si.php';
   $error_url = './no.php';
   $error = '';
   $eol = "\n";
   $max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;
   $boundary = md5(uniqid(time()));

   $header  = 'From: '.$mailfrom.$eol;
   $header .= 'Reply-To: '.$mailfrom.$eol;
   $header .= 'MIME-Version: 1.0'.$eol;
   $header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
   $header .= 'X-Mailer: PHP v'.phpversion().$eol;
   if (!ValidateEmail($mailfrom))
   {
      $error .= "The specified email address is invalid!\n<br>";
   }

   if (!empty($error))
   {
      $errorcode = file_get_contents($error_url);
      $replace = "##error##";
      $errorcode = str_replace($replace, $error, $errorcode);
      echo $errorcode;
      exit;
   }

   $internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
   $message .= $eol;
   $message .= "IP Address : ";
   $message .= $_SERVER['REMOTE_ADDR'];
   $message .= $eol;
   $logdata = '';
   foreach ($_POST as $key => $value)
   {
      if (!in_array(strtolower($key), $internalfields))
      {
         if (!is_array($value))
         {
            $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
         }
         else
         {
            $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
         }
      }
   }
   $body  = 'This is a multi-part message in MIME format.'.$eol.$eol;
   $body .= '--'.$boundary.$eol;
   $body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
   $body .= 'Content-Transfer-Encoding: 8bit'.$eol;
   $body .= $eol.stripslashes($message).$eol;
   if (!empty($_FILES))
   {
       foreach ($_FILES as $key => $value)
       {
          if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)
          {
             $body .= '--'.$boundary.$eol;
             $body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
             $body .= 'Content-Transfer-Encoding: base64'.$eol;
             $body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
             $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
          }
      }
   }
   $body .= '--'.$boundary.'--'.$eol;
   if ($mailto != '')
   {
      mail($mailto, $subject, $body, $header);
   }
   header('Location: '.$success_url);
   exit;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Daruma Tattoo Studio</title>
<meta name="generator" content="WYSIWYG Web Builder 11 - http://www.wysiwygwebbuilder.com">
<link href="Untitled1.css" rel="stylesheet">
<link href="contacto.css" rel="stylesheet">
</head>
<body>
<div id="space"><br></div>
<div id="container">
<div id="wb_Image1" style="position:absolute;left:0px;top:0px;width:763px;height:763px;filter:alpha(opacity=10);opacity:0.10;z-index:12;">
<img src="images/daruma logo.png" id="Image1" alt=""></div>
<div id="wb_Form1" style="position:absolute;left:94px;top:166px;width:575px;height:400px;z-index:14;">
<form name="Contacto_web" method="post" action="<?php echo basename(__FILE__); ?>" enctype="multipart/form-data" id="Form1">
<input type="hidden" name="formid" value="form1">
<div id="wb_Shape1" style="position:absolute;left:10px;top:311px;width:138px;height:26px;z-index:0;">
<img src="images/img0002.png" id="Shape1" alt="" style="width:138px;height:26px;"></div>
<input type="text" id="Editbox1" style="position:absolute;left:10px;top:20px;width:256px;height:18px;line-height:18px;z-index:1;" name="Nombre : " value="" placeholder="Nombre">
<input type="email" id="Editbox2" style="position:absolute;left:301px;top:20px;width:254px;height:18px;line-height:18px;z-index:2;" name="Email : " value="" placeholder="Email">
<input type="number" id="Editbox3" style="position:absolute;left:10px;top:61px;width:256px;height:18px;line-height:18px;z-index:3;" name="Fono : " value="" placeholder="Fono">
<label for="FileUpload1" id="Label5" style="position:absolute;left:12px;top:311px;width:140px;height:18px;line-height:18px;z-index:4;">Imagen de Referencia</label>
<input type="file" id="FileUpload1" style="position:absolute;left:158px;top:312px;width:405px;height:23px;line-height:23px;z-index:5;" name="imagen de referencia">
<input type="reset" id="Button1" name="Borrar Todo" value="Borrar Todo" style="position:absolute;left:158px;top:362px;width:96px;height:25px;z-index:6;">
<input type="submit" id="Button2" name="Enviar" value="Enviar" style="position:absolute;left:469px;top:362px;width:96px;height:25px;z-index:7;">
<textarea name="Detalle del tatuaje" id="TextArea1" style="position:absolute;left:10px;top:152px;width:545px;height:137px;z-index:8;" rows="7" cols="88" placeholder="Detallanos que deseas tatuarte"></textarea>
<input type="text" id="Editbox4" style="position:absolute;left:301px;top:61px;width:254px;height:18px;line-height:18px;z-index:9;" name="Zona a tatuar : " value="" placeholder="Zona a Tatuar">
<input type="text" id="Editbox5" style="position:absolute;left:10px;top:104px;width:256px;height:18px;line-height:18px;z-index:10;" name="Medida : " value="" placeholder="Medidas Aprox del Tatuaje">
<input type="text" id="Editbox6" style="position:absolute;left:301px;top:104px;width:254px;height:18px;line-height:18px;z-index:11;" name="Colores o Grises : " value="" placeholder="Colores o Grises">
</form>
</div>
<div id="wb_Shape2" style="position:absolute;left:93px;top:66px;width:576px;height:100px;filter:alpha(opacity=23);opacity:0.23;z-index:15;">
<img src="images/img0003.png" id="Shape2" alt="" style="width:576px;height:100px;"></div>
<div id="wb_Image2" style="position:absolute;left:119px;top:72px;width:525px;height:88px;filter:alpha(opacity=70);opacity:0.70;z-index:16;">
<img src="images/bnm.png" id="Image2" alt=""></div>
</div>
</body>
</html>