<?php

use PHPMailer\PHPMailer\PHPMailer;
require '../vendor/autoload.php';

$name = $_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$local = $_POST['para'];
$service = $_POST['tipo'];
$message = $_POST['message'];

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "contacto@drenax.com.mx";
//Password to use for SMTP authentication
$mail->Password = "Drenax.123!";
//Set who the message is to be sent from
$mail->setFrom('contacto@drenax.com.mx', 'Desde WEB drenax.com.mx');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress($email, $name);
//Set the subject line
$mail->Subject = $service;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'));
//Replace the plain text body with one created manually
$mail->Body = $message.' '.$name.' '.$tel;
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.webp');
//send the message, check for errors
if (!$mail->send()) {
    http_response_code(500);
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    http_response_code(200);
    echo "Message sent!";
    //Section 2: IMAP
    //Uncomment these to save your message in the 'Sent Mail' folder.
    #if (save_mail($mail)) {
    #    echo "Message saved!";
    #}
}
?>