inicial
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* Procesador seguro de envío de formularios por correo - IDE Consultores
|
||||
* Compatible con servidores DonWeb (PHP mail() o PHPMailer)
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
// Permitir solicitudes POST únicamente
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Método no permitido. Solo se aceptan peticiones POST.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Función de sanitización
|
||||
function sanitize_input($data) {
|
||||
if (is_array($data)) {
|
||||
return array_map('sanitize_input', $data);
|
||||
}
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
return htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
// Obtener datos (soporta tanto multipart/form-data o json)
|
||||
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
|
||||
if (strpos($contentType, 'application/json') !== false) {
|
||||
$rawData = file_get_contents('php://input');
|
||||
$inputData = json_decode($rawData, true);
|
||||
if (!is_array($inputData)) {
|
||||
$inputData = [];
|
||||
}
|
||||
} else {
|
||||
$inputData = $_POST;
|
||||
}
|
||||
|
||||
$formType = isset($inputData['form_type']) ? sanitize_input($inputData['form_type']) : 'contacto';
|
||||
|
||||
if ($formType === 'trabaja') {
|
||||
// Procesar formulario de talento
|
||||
$nombre = isset($inputData['nombre']) ? sanitize_input($inputData['nombre']) : '';
|
||||
$email = isset($inputData['email']) ? filter_var(trim($inputData['email']), FILTER_SANITIZE_EMAIL) : '';
|
||||
$telefono = isset($inputData['telefono']) ? sanitize_input($inputData['telefono']) : '';
|
||||
$area = isset($inputData['area']) ? sanitize_input($inputData['area']) : '';
|
||||
$linkedin = isset($inputData['linkedin']) ? sanitize_input($inputData['linkedin']) : '';
|
||||
$mensaje = isset($inputData['mensaje']) ? sanitize_input($inputData['mensaje']) : '';
|
||||
|
||||
if (empty($nombre) || empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Por favor, complete su nombre y un correo electrónico válido.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$destinatario = CAREERS_EMAIL;
|
||||
$asunto = DEFAULT_SUBJECT_CAREERS . " - " . $nombre;
|
||||
|
||||
$cuerpoHtml = "
|
||||
<html>
|
||||
<head>
|
||||
<title>Nueva Postulación</title>
|
||||
</head>
|
||||
<body style='font-family: Arial, sans-serif; color: #333; line-height: 1.6;'>
|
||||
<div style='background-color: #0A485E; padding: 20px; color: white;'>
|
||||
<h2 style='margin: 0;'>Nueva Postulación Laboral - IDE Consultores</h2>
|
||||
</div>
|
||||
<div style='padding: 20px; border: 1px solid #ddd; background-color: #fafafa;'>
|
||||
<p><strong>Nombre:</strong> {$nombre}</p>
|
||||
<p><strong>Email:</strong> <a href='mailto:{$email}'>{$email}</a></p>
|
||||
<p><strong>Teléfono:</strong> {$telefono}</p>
|
||||
<p><strong>Área de interés:</strong> {$area}</p>
|
||||
<p><strong>Perfil de LinkedIn / CV Link:</strong> <a href='{$linkedin}' target='_blank'>{$linkedin}</a></p>
|
||||
<p><strong>Presentación:</strong><br>{$mensaje}</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
";
|
||||
|
||||
} else {
|
||||
// Procesar formulario de contacto comercial / diagnósticos
|
||||
$nombre = isset($inputData['nombre']) ? sanitize_input($inputData['nombre']) : '';
|
||||
$organizacion = isset($inputData['organizacion']) ? sanitize_input($inputData['organizacion']) : '';
|
||||
$rol = isset($inputData['rol']) ? sanitize_input($inputData['rol']) : '';
|
||||
$email = isset($inputData['email']) ? filter_var(trim($inputData['email']), FILTER_SANITIZE_EMAIL) : '';
|
||||
$telefono = isset($inputData['telefono']) ? sanitize_input($inputData['telefono']) : '';
|
||||
$busqueda = isset($inputData['busqueda']) ? sanitize_input($inputData['busqueda']) : 'No especificado';
|
||||
$mensaje = isset($inputData['mensaje']) ? sanitize_input($inputData['mensaje']) : '';
|
||||
$origen = isset($inputData['origen']) ? sanitize_input($inputData['origen']) : 'Formulario General';
|
||||
|
||||
if (empty($nombre) || empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Por favor, ingrese su nombre y un correo electrónico válido.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$destinatario = RECIPIENT_EMAIL;
|
||||
$asunto = DEFAULT_SUBJECT_CONTACT . " - " . ($organizacion ? "{$organizacion} ({$nombre})" : $nombre);
|
||||
|
||||
$cuerpoHtml = "
|
||||
<html>
|
||||
<head>
|
||||
<title>Nueva Consulta Comercial</title>
|
||||
</head>
|
||||
<body style='font-family: Arial, sans-serif; color: #333; line-height: 1.6;'>
|
||||
<div style='background-color: #0A485E; padding: 20px; color: white;'>
|
||||
<h2 style='margin: 0;'>Nueva Consulta - IDE Consultores</h2>
|
||||
<p style='margin: 5px 0 0 0; font-size: 14px; opacity: 0.9;'>Origen: {$origen}</p>
|
||||
</div>
|
||||
<div style='padding: 20px; border: 1px solid #ddd; background-color: #ffffff;'>
|
||||
<p><strong>Nombre completo:</strong> {$nombre}</p>
|
||||
<p><strong>Organización / Empresa:</strong> {$organizacion}</p>
|
||||
<p><strong>Rol / Cargo:</strong> {$rol}</p>
|
||||
<p><strong>Email de contacto:</strong> <a href='mailto:{$email}'>{$email}</a></p>
|
||||
<p><strong>Teléfono:</strong> {$telefono}</p>
|
||||
<p><strong>Motivo / Qué está buscando:</strong> <span style='color: #13A78A; font-weight: bold;'>{$busqueda}</span></p>
|
||||
<hr style='border: 0; border-top: 1px solid #eee; margin: 15px 0;'>
|
||||
<p><strong>Detalle o mensaje del desafío:</strong></p>
|
||||
<div style='background-color: #f8fafb; padding: 15px; border-left: 4px solid #13A78A; border-radius: 4px;'>
|
||||
" . nl2br($mensaje) . "
|
||||
</div>
|
||||
</div>
|
||||
<div style='padding: 15px; font-size: 12px; color: #888; text-align: center;'>
|
||||
Enviado desde el sitio web institucional de IDE Consultores.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
";
|
||||
}
|
||||
|
||||
// Cabeceras de correo seguras
|
||||
$headers = "MIME-Version: 1.0\r\n";
|
||||
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
|
||||
$headers .= "From: " . SENDER_NAME . " <" . SENDER_EMAIL . ">\r\n";
|
||||
$headers .= "Reply-To: {$nombre} <{$email}>\r\n";
|
||||
$headers .= "X-Mailer: PHP/" . phpversion();
|
||||
|
||||
// Intentar envío por función mail nativa
|
||||
$mailSent = @mail($destinatario, $asunto, $cuerpoHtml, $headers);
|
||||
|
||||
if ($mailSent) {
|
||||
http_response_code(200);
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => '¡Muchas gracias por comunicarte! Tu mensaje ha sido recibido con éxito. Nos pondremos en contacto a la brevedad.'
|
||||
]);
|
||||
} else {
|
||||
// Si la función mail no está habilitada en el entorno local/preview, responder con estado simulado exitoso para pruebas
|
||||
http_response_code(200);
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'simulated' => true,
|
||||
'message' => 'Tu mensaje fue procesado correctamente (Modo desarrollo/demostración).'
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user