Buenas y ante todo gracias por la ayuda!! Tengo mi web realizada donde tengo un Formulario de contacto que tiene un botón "enviar" que se activa cuando se completan los campos del formulario (para esto apliqué el javascript:
<!-- Script para validar el Formulario -->
<script>
function validar(frm) {
frm.sub.disabled = true;
for (i=0; i<4; i++)
if (frm['txt'+i].value =='') return
frm.sub.disabled = false;
}
</script>
y cuando lo pruebo desde computadoras varias y diferentes celulares funciona perfecto. Pero recibo correos vacíos hace semana y no encuentro realmente el error. Dejo el código completo de mi formulario:
<section class="contacto py-2 text-center col-md-7">
<div class="container">
<h2 class="h3 my-3">CONTACTO</h2>
<form action="mail/mail.php" method="post">
<div class="form-row">
<div class="form-group col-md-9 d-flex align-items-center">
<p class="hicon"><i class="fas fa-hotel"></i></p>
<input type="text" class="form-control" name="txt0" placeholder="Hotel" onkeyup = "validar(this.form)">
</div>
<div class="form-group col-md-3 d-flex align-items-center">
<p class="hicon"><i class="fas fa-door-open"></i></p>
<input type="number" class="form-control" name="txt1" placeholder="Habitaciones" onkeyup = "validar(this.form)">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6 d-flex align-items-center">
<p class="hicon"><i class="far fa-user"></i></p>
<input type="text" class="form-control" name="txt2" placeholder="Nombre" onkeyup = "validar(this.form)">
</div>
<div class="form-group col-md-6 d-flex align-items-center">
<p class="hicon"><i class="fas fa-at"></i></p>
<input type="email" class="form-control" name="txt3" placeholder="Email" onkeyup = "validar(this.form)">
</div>
</div>
<div class="form-row">
<div class="form-group col-12 d-flex align-items-center">
<p class="hicon"><i class="fas fa-globe-americas"></i></p>
<input type="web" class="form-control" name="txt4" placeholder="Web">
</div>
</div>
<div class="form-row">
<div class="form-group col-12 d-flex align-items-center">
<p class="hicon"><i class="fas fa-align-left"></i></p>
<input type="texttarea" class="form-control" name="inputMsg" placeholder="Consulta...">
</div>
</div>
<div class="form-row">
<div class="form-group col-12 d-flex align-items-center">
<button type="submit" class="btn btn-primary mb-2 w-100" name="sub" disabled="disabled" data-placement="top" title="Completar los datos para habilitar el botón" data-toggle="modal" data-target="#send">Enviar</button>
</div>
</div>
</form>
</div>
</section>
y este es el mail.php, que es el básico de phpmailer para enviar un mail con mis datos:
<?php
$Hotel = $_POST["txt0"];
$Hab = $_POST["txt1"];
$Nombre = $_POST["txt2"];
$Email = $_POST["txt3"];
$Web = $_POST["txt4"];
$Mensaje = $_POST["inputMsg"];
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
// $mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted ssl
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->Username = 'mimail@gmail.com'; // SMTP username
$mail->Password = 'mipass'; // SMTP password
$mail->Port = 587; // TCP port to connect to 465
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Recipients
$mail->setFrom('mimail@gmail.com');
$mail->addAddress('info@hotelop.com'); // Add a recipient
$mail->addReplyTo('info@hotelop.com');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
// Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Nuevo Contacto';
$mail->Body = 'Nombre: ' . $Nombre . '<br>Hotel: '. $Hotel . '<br>Hab: '. $Hab . '<br>Email: '. $Email . '<br>Web: '. $Web . '<br>Mensaje: '. $Mensaje;
$mail->AltBody = '';
$mail->send();
echo 'Enviado';
header('location:../index.html');
exit;
} catch (Exception $e) {
echo "MAL. Mailer Error: {$mail->ErrorInfo}";
}
?>
Gracias de ante mano. Seba
Nombre:
,Hotel:
etc, sin nada al lado? – A. Cedano el 27 sep. 19 a las 21:35$mail->AltBody = '';
puede que te esté cambiando el body por nada debido a esa línea. – A. Cedano el 27 sep. 19 a las 21:38