<?php
// 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;

require 'mailer/Exception.php';
require 'mailer/PHPMailer.php';
require 'mailer/SMTP.php';

$message = isset($_POST['message']) ? $_POST["message"]  : "";
$email = isset($_POST['email']) ? $_POST["email"]  : "";
$first = isset($_POST['first']) ? $_POST["first"]  : "";
$last = isset($_POST['last']) ? $_POST["last"]  : "";

if( $message == "" || $email == "" || ( $first == "" && $last == "" ) ) {
   echo "0";
   return;
}

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
//    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->SMTPDebug = 0;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->isHTML(true) ;
    $mail->Host = 'box.interactivos.net.ar';              // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'contact@deckertstore.com';         // SMTP username
    $mail->Password = 'sedeco12';                         // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable SSL encryption, TLS also accepted with port 465
    $mail->Port = 465;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('contact@deckertstore.com', 'Deckert Contact Form');     //This is the email your form sends From
    $mail->addAddress('ag@deckertstore.com', '');            // Add a recipient address
    $mail->addAddress("pb@deckertstore.com", '');
    $mail->addReplyTo($email, 'Deckert Store');
    //$mail->addAddress('contact@example.com');                     // Name is optional
    //$mail->addReplyTo('info@example.com', 'Information');
    //$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 = 'Message From Deckertstore';
    $mail->Body    = 'Message From Deckertstore Form sended from ' . $email . " " . $first . " " . $last . "<br><br>" . $message;
    //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo(1);
//  echo 'Message has been sent';
   return;
} catch (Exception $e) {
    echo(0);
   return;
//  echo 'Mailer Error: ' . $mail->ErrorInfo;
}

?>

