// 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;
$nombre = $_POST['nombre'];
$apellido = $_POST['apellido'];
$email = $_POST['email_real'];
$telefono = $_POST['telefono'];
$mensaje = $_POST['mensaje'];
// robot detection
$honeypot = trim($_POST["email"]);
if(!empty($honeypot)) {
echo "BAD ROBOT!";
exit;
}
//Load Composer's autoloader
require 'phpmailer/vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'fmrga3@gmail.com';
$mail->Password = 'ehxetezllnhggqjm';
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('fmrga3@gmail.com', 'Sitio Remogal');
$mail->addAddress('info@remogal.com'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Contacto Remogal';
$mail->Body = "Mensaje recibido de: " . $nombre." ".$apellido." Su correo es: ". $email ." Su numero de celular es: " .$telefono. "Mensaje: ".$mensaje. " Enviado el " . date('d/m/Y', time())."";
$mail->send();
header("Location: gracias.html");
} catch (Exception $e) {
echo 'Error al enviar el mensaje: ', $mail->ErrorInfo;
}