<?php 

//======================================================================
// Variables  ventas@sattek.com.co | cas@sattek.com.co
//======================================================================


//E-mail address. Enter your email
define("__TO__", "acandanoza@yahoo.com");

//Success message
define('__SUCCESS_MESSAGE__', "Su mensaje ha sido enviado. Le responderemos a la mayor brevedad posible ¡Gracias!");

//Error message 
define('__ERROR_MESSAGE__', "Su mensaje no ha sido enviado. Por favor, inténtalo de nuevo.");

//Messege when one or more fields are empty
define('__MESSAGE_EMPTY_FIELDS__', "Por favor diligencie todos los campos");


//======================================================================
// Do not change
//======================================================================

//E-mail validation

//Send mail
function send_mail($to,$subject,$message,$headers){
    if(@mail($to,$subject,$message,$headers)){
        echo json_encode(array('info' => 'success', 'msg' => __SUCCESS_MESSAGE__));
    } else {
        echo json_encode(array('info' => 'error', 'msg' => __ERROR_MESSAGE__));
    }
}

//Get data form and send mail - Thank you Rafael for your contribution.
if(isset($_POST['name']) and isset($_POST['emaild']) and isset($_POST['message'])){
	$name = $_POST['name'];
	$mail = $_POST['emaild'];
	$subjectForm = $_POST['subject'];
	$messageForm = $_POST['message'];

    if($name == '') {
        echo json_encode(array('info' => 'error', 'msg' => "Por favor registre su nombre."));
        exit();
    } else if($messageForm == ''){
        echo json_encode(array('info' => 'error', 'msg' => "Por favor registre su mensaje."));
        exit();
    } else {
        $to = __TO__;
        $subject = $subjectForm . ' ' . $name;
        $message = '
        <html>
        <head>
          <title>Mail from '. $name .'</title>
        </head>
        <body>
          <table style="width: 500px; font-family: arial; font-size: 14px;" border="1">
            <tr style="height: 32px;">
              <th align="right" style="width:150px; padding-right:5px;">Nombre:</th>
              <td align="left" style="padding-left:5px; line-height: 20px;">'. $name .'</td>
            </tr>
            <tr style="height: 32px;">
              <th align="right" style="width:150px; padding-right:5px;">E-mail:</th>
              <td align="left" style="padding-left:5px; line-height: 20px;">'. $mail .'</td>
            </tr>
            <tr style="height: 32px;">
              <th align="right" style="width:150px; padding-right:5px;">Razón social o conjunto:</th>
              <td align="left" style="padding-left:5px; line-height: 20px;">'. $subjectForm .'</td>
            </tr>
            <tr style="height: 32px;">
              <th align="right" style="width:150px; padding-right:5px;">Mensaje:</th>
              <td align="left" style="padding-left:5px; line-height: 20px;">'. $messageForm  .'</td>
            </tr>
          </table>
        </body>
        </html>
        ';

        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
        $headers .= 'From: ' . $mail . "\r\n";

        send_mail($to,$subject,$message,$headers);
    }
} else {
    echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FIELDS__));
}
 ?>