// funciones de validacion
function check_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("[^@]{1,64}@[^@]{1,255}", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
function send_mail($to, $body, $subject, $fromaddress, $fromname, $attachments=false)
{
$eol="\r\n";
$mime_boundary="Provehima.com_".md5(time());
# Common Headers
$headers .= "From: ".$fromname."<".$fromaddress.">".$eol;
$headers .= "Reply-To: ".$fromname."<".$fromaddress.">".$eol;
$headers .= "Return-Path: ".$fromname."<".$fromaddress.">".$eol; // these two to set reply address
$headers .= "Message-ID: <".time()."-".$fromaddress.">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol;
# Open the first part of the mail
$msg = "--".$mime_boundary.$eol;
$htmlalt_mime_boundary = $mime_boundary."_htmlalt"; //we must define a different MIME boundary for this section
# Setup for text OR html -
$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol.$eol;
# Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= strip_tags(str_replace(" ", "\n", substr($body, (strpos($body, "")+6)))).$eol.$eol;
# HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= $body.$eol.$eol;
//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol;
if ($attachments !== false)
{
for($i=0; $i < count($attachments); $i++)
{
if (is_file($attachments[$i]["file"]))
{
# File for Attachment
$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
$handle=fopen($attachments[$i]["file"], 'rb');
$f_contents=fread($handle, filesize($attachments[$i]["file"]));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
$f_type=filetype($attachments[$i]["file"]);
fclose($handle);
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol; // sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Description: ".$file_name.$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
}
}
}
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
# SEND THE EMAIL
ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !
$mail_sent = mail($to, $subject, $msg, $headers);
ini_restore(sendmail_from);
return $mail_sent;
}
function construye_destinatario(){
$departamento = $_REQUEST['departamento'];
$provincia = $_REQUEST['provincia'];
$email = $_REQUEST['email'];
$telefono = $_REQUEST['telefono'];
$asunto = $_REQUEST['asunto'];
$mensaje = $_REQUEST['mensaje'];
$tipo = $_REQUEST['tipovehiculos'];
switch($departamento){
case 'taller':
switch($tipo){
case 'turismo':
return "ttur@provehima.com";
break;
case 'camion':
return "taller.".$provincia."@provehima.com";
break;
}
case 'recambios':
switch($provincia){
case "albacete":
return "recambios.albacete@provehima.com";
break;
case "murcia":
return "lop@provehima.com";
break;
case "alicante":
return "asg@provehima.com";
break;
case "cuenca":
return "postventa.cuenca@provehima.com";
break;
}
case "ventas":
if($_REQUEST['turismo']==1){
return "ventas@provehima.com";
}else{
return "ventas.".$provincia."@provehima.com";
}
}
}
function envia_datos($departamento,$provincia, $email, $telefono, $asunto, $mensaje){
//proteccion contra injecciones de codigo para envio masivo de correos
if(!isset($_SERVER['HTTP_USER_AGENT'])){
die("Acceso denegado - No esta autorizado a ver este apartado");
exit;
}
// Make sure the form was indeed POST'ed:
// (requires your html form to use: action="post")
if(!$_SERVER['REQUEST_METHOD'] == "POST"){
die("Acceso denegado - No esta autorizado a ver este apartado");
exit;
}
// Host names from where the form is authorized
// to be posted from:
$authHosts = array("estudioalfa.com", "provehima.com");
// Where have we been posted from?
$fromArray = parse_url(strtolower($_SERVER['HTTP_REFERER']));
// Test to see if the $fromArray used www to get here.
$wwwUsed = strpos($fromArray['host'], "www.");
// Make sure the form was posted from an approved host name.
if(!in_array(($wwwUsed === false ? $fromArray['host'] : substr(stristr($fromArray['host'], '.'), 1)), $authHosts)){
// logBadRequest();
header("HTTP/1.0 403 Forbidden");
exit;
}
// Attempt to defend against header injections:
$badStrings = array("Content-Type:",
"MIME-Version:",
"Content-Transfer-Encoding:",
"bcc:",
"cc:");
// Loop through each POST'ed value and test if it contains
// one of the $badStrings:
foreach($_POST as $k => $v){
foreach($badStrings as $v2){
if(strpos($v, $v2) !== false){
// logBadRequest();
header("HTTP/1.0 403 Forbidden");
exit;
}
}
}
// Made it past spammer test, free up some memory
// and continue rest of script:
unset($k, $v, $v2, $badStrings, $authHosts, $fromArray, $wwwUsed);
if($_REQUEST['turismo']==1){
$destinatario = "ventas@provehima.com";
}else{
$destinatario = $departamento.".".$provincia."@provehima.com";
}
$remitente = $email;
if($_REQUEST['matricula']!="matricula del vehículo" || $_REQUEST['modelo']!="modelo del vehículo"){
$extra_content="
Modelo: ".$_REQUEST['modelo']."
Matricula: ".$_REQUEST['matricula'];
}
$contenido_email="

Se ha recibido la siguiente consulta desde Provehima.com:
Asunto: $asunto
Email de contacto: $remitente
Teléfono de contacto: $telefono
$extra_content
Mensaje:
$mensaje
Que tenga un buen día
Provehima.com ";
$asunto = "Consulta desde Provehima.com: ". $asunto;
send_mail(construye_destinatario(), $contenido_email, $asunto , $remitente, $remitente, false);
//send_mail("contacto@estudioalfa.com", $contenido_email, $asunto , $remitente, $remitente, false);
}
$muestra_formulario=true;
// validacion de los datos de envio
if($_POST['accion']=="validar" || $_GET['provincia']!="" || $_GET['departamento']!="" ){
//inicialiamos las variables de error
$error=false;
$str_error_email ="";
$str_error_departamento ="";
$str_error_provincia ="";
$str_error_mensaje ="";
//recogemos los valores
$departamento = $_REQUEST['departamento'];
$provincia = $_REQUEST['provincia'];
$email = $_REQUEST['email'];
$telefono = $_REQUEST['telefono'];
$asunto = $_REQUEST['asunto'];
$mensaje = $_REQUEST['mensaje'];
if($_REQUEST['departamento']=="ventas"){
$turismo = true;
}else{
$turismo = false;
}
if(!check_email_address($email)){ // si no es un email valido
$error=true;
$str_error_email=" | | Por favor, introduzca un email valido | ";
}
if(trim($departamento)==""){ //si no selecciono el departamento
$error=true;
$str_error_departamento="| Por favor, seleccione un departamento | ";
}
if(trim($provincia)=="" && !$turismo){ // si no selecciono la provincia y es un camion
$error=true;
$str_error_provincia="| Por favor, seleccione la provincia | ";
}
if(trim($mensaje)==""){ // si no escribio el mensaje
$error=true;
$str_error_mensaje="| Por favor, escriba el mensaje | ";
}
if(!isset($_GET['accion'])){
// if($_GET['provincia'] || $_GET['departamento'] ){
$str_error_mensaje="";
$str_error_provincia="";
$str_error_departamento="";
$str_error_email="";
}
if(!$error){
envia_datos($departamento,$provincia, $email, $telefono, $asunto, $mensaje);
$muestra_formulario=false;
}
}
switch($_REQUEST['departamento']){
case "ventas":
$str_mensaje_pagina="";
break;
case "recursos":
$str_mensaje_pagina="";
break;
case "serviciotecnico":
$str_mensaje_pagina="Make an appointment with our workshop to get a personalized service.";
break;
case "postventa":
$str_mensaje_pagina="";
break;
case "citaprevia":
$str_mensaje_pagina="Make an appointment with our workshop to get a personalized service.";
break;
case "taller":
$str_mensaje_pagina="Make an appointment with our workshop to get a personalized service.";
break;
case "recambios":
$str_mensaje_pagina="Make an appointment with our workshop to get a personalized service.";
break;
}
if($muestra_formulario){
?>
}else{ ?>
Request successfully sent. We will contact you soon.
} ?>
|