<?php
session_start();
$_SESSION['email'] = $_POST['email'];
$email = $_SESSION['email'];
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';

// Instantiation and passing [ICODE]true[/ICODE] enables exceptions
$mail = new PHPMailer(true);

try {
    
    $mail->isSMTP();                                                // Set mailer to use SMTP
    $mail->Host       = 'mail.enzalada.ph';                         // Specify main and backup SMTP servers
    $mail->SMTPAuth   = true;                                       // Enable SMTP authentication
    $mail->Username   = 'jomell@enzalada.ph';                       // SMTP username
    $mail->Password   = 'ftj88belv2qh';                             // SMTP password
    $mail->SMTPSecure = 'ssl';                                      // Enable TLS encryption, [ICODE]ssl[/ICODE] also accepted
    $mail->Port       = 465;                                        // TCP port to connect to

    //Recipients
    $mail->setFrom('verify.user-notification@enzalada.ph', 'Enzalada');
    $mail->addAddress($email);                                      // Add a recipient
    $mail->addReplyTo('verify.user-notification@enzalada.ph', 'Enzalada');

    // // Attachments
    // $mail->addAttachment('/home/cpanelusername/attachment.txt');         // Add attachments
    // $mail->addAttachment('/home/cpanelusername/image.jpg', 'new.jpg');    // Optional name

    // Content
    $mail->isHTML(true);                                            // Set email format to HTML
    $mail->Subject = 'OTP Enzalada - Forgot Password';                                                                                                       //localhost //www.enzalada.ph
    $mail->Body    = 'Password change request - If this is not from you, kindly ignore this email!<br> proceed with resetting email thru this link. -  https://localhost/Enzalada/forgot-password-reset.php?password-reset-mailed';


    $mail->send();
    header("Location: ../reset-password-mail.php?password-reset-mailed");

} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}