0) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $idioma = $jsonSolicitud['idioma']; $necesito = $jsonSolicitud['necesito']; $nombre = $jsonSolicitud['nombre']; $apellidos = $jsonSolicitud['apellido']; $cargo = $jsonSolicitud['cargo']; $empresa = $jsonSolicitud['empresa']; $pais = $jsonSolicitud['pais']; $telefono = $jsonSolicitud['telefono']; if(empty($jsonSolicitud['estado'])){ $estado = ''; }else{ $estado = $jsonSolicitud['estado']; } $email = $jsonSolicitud['email']; $comentarios = $jsonSolicitud['comentarios']; $datetime = strftime("%d/%m/%Y %H:%M"); $recaptcha_response = $jsonSolicitud['captcha']; if (!empty($_SERVER['HTTP_CLIENT_IP'])){ $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; }else{ $ip = $_SERVER['REMOTE_ADDR']; } // Realizamos la petición de control: $recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify'; $recaptcha_secret = '6LfGubMZAAAAALSNDYiOV44Me6zPJ-0e0gak1x-u'; $recaptchaGet = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response); $recaptcha = json_decode($recaptchaGet,true); // Miramos si se considera humano o robot: // echo json_encode($recaptcha); if ($recaptcha['success'] == true) { if($recaptcha['score'] >= 0.1){ // enviamos el correo enviarCorreo($necesito,$nombre,$apellidos,$cargo,$empresa,$pais,$telefono,$estado,$email,$comentarios,$ip,$datetime,$idioma); }else{ if($idioma == 'es'){ $msj = "No hemos podido descubrir que eres un humano, por favor recarga la página"; }else if($idioma == 'en'){ $msj = "We have not been able to discover that you are a human, please reload the page"; } controlError(false, $msj); } }else{ if($idioma == 'es'){ $msj = "Captcha repetido o invalido, favor de recargar la Página."; }else if($idioma == 'en'){ $msj = "Repeated or invalid Captcha, please reload the page."; } controlError(false,$msj); } } } function enviarCorreo($necesito,$nombre,$apellidos,$cargo,$empresa,$pais,$telefono,$estado,$email,$comentarios,$ip,$datetime,$idioma){ $mail = new PHPMailer; //Enable SMTP debugging. $mail->SMTPDebug = 3; //Set PHPMailer to use SMTP. $mail->isSMTP(); //Set SMTP host name $mail->Host = "smtp.com"; //Set this to true if SMTP host requires authentication to send email $mail->SMTPAuth = true; //Provide username and password $mail->Username = "web.plataforma.educativa@ittec.mx"; $mail->Password = "UJG4bH2Z3S^C"; //If SMTP requires TLS encryption then set it $mail->SMTPSecure = "tls"; //Set TCP port to connect to $mail->Port = 2525; $mail->From = "web.plataforma.educativa@ittec.mx"; $mail->FromName = "Sitio Web ITTEC"; $mail->addAddress("alejandro.l@ittec.mx","Centro de Soluciones"); // $mail->addAddress("soluciones@ittec.mx","Centro de Soluciones"); $mail->isHTML(true); $mail->Subject = "Contacto - ".$necesito; $mail->Body = "IP: ".$ip."
". "Nombre: ".$nombre." ".$apellidos."
". "Cargo: ".$cargo."
". "Empresa: ".$empresa."
". "País: ".$pais."
". "Teléfono: ".$telefono."
". "Estado: ".$estado."
". "Correo electónico: ".$email."
". "Fecha y Hora: ".$datetime."
". "Comentarios: ".$comentarios."
"; $mail->CharSet = 'UTF-8'; $mail->SMTPDebug = 0; // $mail->AltBody = "This is the plain text version of the email content"; if(!$mail->send()){ if($idioma == 'es'){ $msj = "No se ha podido enviar el email, intenta más tarde."; }else if($idioma == 'en'){ $msj = "The email could not be sent, please try again later."; } controlError(false, $msj); // echo "Mailer Error: " . $mail->ErrorInfo; }else{ if($idioma == 'es'){ $msj = "La demanda de contacto ha sido enviada exitosamente."; }else if($idioma == 'en'){ $msj = "The contact request has been sent successfully."; } controlError(true, $msj); } } function controlError($succes,$mensaje) { $response = array('success'=>$succes,'mensaje'=>$mensaje); echo json_encode($response); } ?>