| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\SMTP;
- use PHPMailer\PHPMailer\Exception;
- require '../vendor/autoload.php';
- header("Content-type: application/json; charset=utf-8");
- $jsonSolicitud = json_decode(file_get_contents('php://input'), true);
- if (count($jsonSolicitud) > 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 = "<strong>IP: </strong>".$ip."<br>".
- "<strong>Nombre: </strong>".$nombre." ".$apellidos."<br>".
- "<strong>Cargo: </strong>".$cargo."<br>".
- "<strong>Empresa: </strong>".$empresa."<br>".
- "<strong>País: </strong>".$pais."<br>".
- "<strong>Teléfono: </strong>".$telefono."<br>".
- "<strong>Estado: </strong>".$estado."<br>".
- "<strong>Correo electónico: </strong>".$email."<br>".
- "<strong>Fecha y Hora: </strong>".$datetime."<br>".
- "<strong>Comentarios: </strong>".$comentarios."<br>";
- $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);
- }
- ?>
|