| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\SMTP;
- use PHPMailer\PHPMailer\Exception;
- require '../vendor/autoload.php';
- if (isset($_POST['necesito'])) {
- $necesito = $_POST['necesito'];
- $nombre = $_POST['nombre'];
- $apellidos = $_POST['apellido'];
- $cargo = $_POST['cargo'];
- $empresa = $_POST['empresa'];
- $direccion = $_POST['direccion'];
- $cp = $_POST['cp'];
- $ciudad = $_POST['ciudad'];
- $pais = $_POST['pais'];
- $telefono = $_POST['telefono'];
- if(empty($_POST['estado'])){
- $estado = '';
- }else{
- $estado = $_POST['estado'];
- }
- $email = $_POST['email'];
- $comentarios = $_POST['comentarios'];
- $datetime = strftime("%d/%m/%Y %H:%M");
- $recaptcha_response = $_POST['recaptcha_response'];
- 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 = '6LelvrMZAAAAAP1h1tJjDhephX1Vy8980qKT4ONn';
- $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,$direccion,$cp,$ciudad,$pais,$telefono,$estado,$email,$comentarios,$ip,$datetime);
- }else{
- controlError(false,"No hemos podido descubrir que eres un humano, por favor recarga la Página");
- }
- }else{
- controlError(false,"Captcha repetido o invalido, favor de recargar la Página.");
- }
-
- }
- function enviarCorreo($necesito,$nombre,$apellidos,$cargo,$empresa,$direccion,$cp,$ciudad,$pais,$telefono,$estado,$email,$comentarios,$ip,$datetime){
- $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 Plataforma Educativa";
- // $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>Institución Educativa: </strong>".$empresa."<br>".
- "<strong>Dirección: </strong>".$direccion.", ".$cp."<br>".
- "<strong>Ciudad: </strong>".$ciudad."<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()){
- controlError(false, "No se ha podido enviar el email, intenta más tarde.");
- // echo "Mailer Error: " . $mail->ErrorInfo;
- }
- else{
- controlError(true, "La demanda de contacto ha sido enviada exitosamente.");
- }
- }
- function controlError($succes,$mensaje) {
- $response = array('success'=>$succes,'mensaje'=>$mensaje);
- echo json_encode($response);
- }
- ?>
|